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

  • Home
  • SEARCH
  • 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 9238577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:47:41+00:00 2026-06-18T07:47:41+00:00

Hi i am using DOM for retrieving the data from an xml file. The

  • 0

Hi i am using DOM for retrieving the data from an xml file. The code below is working perfectly fine for the xml file, but the main problem i am facing is that it recognizes only the root nodes, it does not recognizes child nodes.
Here’s my code:-

 $dom = new DOMDocument();
    $dom->load($url);
    $link = $dom->getElementsByTagName($tag_name);
    $value = array();
for ($i = 0; $i < $link->length; $i++) {
            $childnode['name']=$link->item($i)->nodeName;
            $childnode['value']=$link->item($i)->nodeValue;
            $value[ $childnode['name']] = $childnode['value'];
        // echo $link->item($i)->nodeValue . '<br>';
       $k++;
    }

This is my view file where i am displaying the data

foreach($value as $node=>$value)
{
echo "<b> Node :</b>".$node."<br /><b>Value:</b>".$value."<br /><hr>";
}

This is my xml file

<name>John</name>
<place>Australia</place>
<contact> 
<phone>8734563485</phone> 
<type>Mobile</type> 
</contact>
<mail>somedata</mail>

I am able to read the parent nodes i,e name, place,contact,mail. But i am unable to read child nodes i,e phone,type.
Can anyone plz help me with the code….

  • 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-06-18T07:47:42+00:00Added an answer on June 18, 2026 at 7:47 am

    because you are not traversing the child nodes of course.
    I would create a function and traverse it recursive.

     function addNodesToValue($value,$nodelist) {
       for ($i = 0; $i < $nodelist->length; $i++) {
         $childnode['name']=$nodelist->item($i)->nodeName;
         $childnode['value']=$nodelist->item($i)->nodeValue;
         $value[ $childnode['name']] = $childnode['value'];
         // recursive traverse child nodes
         if($nodelist->item($i)->hasChildNodes()){
           $value = addNodesToValue($value,$nodelist->item($i)->childNodes);
         }
        }
        return $value;
     } 
    
    //usage
    $value = addNodesToValue($value,$link);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DOM parser to parse xml data, but its taking lots of
I want to modify xml file using dom ,but when I make node.getNodeValue(); it
I'm using DOM to parse an xml file. And I am having trouble catching
I want to parse the xml file with dynamic content using DOM parser in
Ho to make this simple xml with php using DOM? Full code will be
I am using the DOM extension to parse an xml file containing xml namespaces
Give me an example on how to parse a custom xml file using DOM
In my java code,I am retrieving some multibyte data from database and making some
Using the example below. I have an HTML file parsed using Mojo::DOM . However
I need to create an XML file using DOM under Eclipse (for Java) and

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.