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 7642979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:19:48+00:00 2026-05-31T09:19:48+00:00

Okay here is a very common xml parsing method, getting child nodes, but it’s

  • 0

Okay here is a very common xml parsing method, getting child nodes, but it’s just not working how it should for me…

I CANNOT get an array of childNodes from my root element here, but I can get it from any other node when they have children, that’s not a problem. It’s whenever I encounter getting childnodes from this document element that I can’t seem to get more than just the very first child.

I need to get all the first level nodes from document element..

$xdoc=createDOMDocument($file);
$all_children= $xdoc->documentElement->childNodes;
echo count($all_children);

function createDOMDocument($file){
    $xdoc = new DOMDocument();
    $xdoc->formatOutput = true;
    $xdoc->preserveWhiteSpace  = false;
    $xdoc->load($file);
    return $xdoc;
}

But this will only ever output “1”, it doesn’t find all the nodes, it always stops at the first node when I’m trying to output it. This makes no sense to me.

The only node it ever finds below is:

<title>some title</title>

If I delete that node, it will find topicmeta and so on, but never every node into an array which is what I need.

Here’s the XML:

<?xml version="1.0" encoding="UTF-8"?>
<map title="mytitle" xml:lang="en-us">
<title>some title</title>
<topicmeta>
<prodinfo>
  <prodname>a product</prodname>
      <vrmlist>
        <vrm version="8.5"/>
      </vrmlist>
  <platform/>
</prodinfo>
 </topicmeta>
  <topichead navtitle="cat1" id="topichead4f53aeb751c875.38130575">
<topichead navtitle="another topic"/>
</topichead>
  <topichead navtitle="cat2" id="topichead4f53aeb3596990.18552413"/>
  <topichead navtitle="cat3" id="topichead4f52fd157487f9.21599660"/>
</map>
  • 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-31T09:19:49+00:00Added an answer on May 31, 2026 at 9:19 am

    This works for me …

    $xml = new DOMDocument();
    $xml->load('read.xml');
    
    $root = $xml->documentElement;
    foreach($root->childNodes as $node){
        print $node->nodeName.' - '.$node->nodeValue;
    }
    

    I did have to change <topichead navtitle="cat3" id="topichead4f52fd157487f9.21599660"> to <topichead navtitle="cat3" id="topichead4f52fd157487f9.21599660" />

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I have seen some very similar questions here but none seem to be
Okay, Here is what I'm trying to do... Right now it is compiling but
Okay, this is (probably) a very simple question, but I am afraid I know
Okay, not sure what I'm doing here, other than it's not right. Trying to
Okay maybe i just need another set of eyes on this, but I have
Okay, this might be a very silly beginner question, but: I've got an ClassA,
Okay, let's start with this very simple button click method private void button1_Click(object sender,
Okay, just for starters, I am very new to Objective-C, (C in general). I
Okay so here is my situation. About a year ago I released my very
Okay, here is a very simple and fundamental question. If I have an application

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.