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>