Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4231822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:01:05+00:00 2026-05-21T02:01:05+00:00

I have an XML file shown below: <?xml version=1.0 encoding=UTF-8?> <xml> <job> <id>4200021</id> <sector>Downtown</sector>

  • 0

I have an XML file shown below:

<?xml version="1.0" encoding="UTF-8"?>
<xml>
    <job>
        <id>4200021</id>
        <sector>Downtown</sector>
        <title>Clean Windows</title>
    </job>

    <job>
        <id>2100021</id>
        <sector>Downtown</sector>
        <title>Fix Manholes</title>
    </job>
</xml>

I’m using PHP’s DOMDocument, and I’m trying to get the <id> of the job by searching the title.

I use this to get the <job> node in question:

$job = $jobDoc->getElementsByTagName('Clean Windows')->item(0)->parentNode;

However, I have iterate through all the nodes by calling nodeName for each node to get the correct ID, is there another simpler way to find the correct id using DOMDocument? I can’t call getElementsByTagName() again on the parentNode, and doing this manually becomes a problem when I have to search once again, within another node to find the in the node , which is part of the nodes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:01:05+00:00Added an answer on May 21, 2026 at 2:01 am
    $doc = new DOMDocument();
    $doc->loadXML($your_xml);
    $x = new DOMXPath($doc);
    $id = $x->query("//title[. = 'Clean Windows']/../id/text()")->item(0)->wholeText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple XML file as shown below. <?xml version=1.0 encoding=UTF-8?> <myConfig> <datasets>
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have a app.config file that in the form of : <?xml version=1.0 encoding=utf-8
I have defined a xml schema as below <?xml version=1.0 encoding=utf-8?> <xs:schema id=PacketTemplate targetNamespace=http://tempuri.org/PacketTemplate.xsd
i have an xml file sitemap.xml as shown below ..i need to add one
I have a bit of xml file named Sample.xml which is shown below <?xml
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
What is the easiest way to convert xml to html? I have xml file
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file providing data for a datagrid in Flex 2 that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.