Hi,
I just started using XML in php and want to use www.php.net/xmldom
But somehow it is not working like expected and I don't know why... Would be great if someone here can give me some hints:
I want to parse an RSS file:
(The url is in $url, the file is a valid xml file with all the child nodes, so the file is ok)
$xml=domxml_open_file($url);
$node=$xml->document_element();
echo $node->tagname();
so far this is working, the output is 'rss', everything fine. But now I want to move one level down:
$node2=$node->first_child();
echo $node2->tagname();
HERE IS THE PROBLEM: no output. $node2 is null! Why? The child node is 'channel', I can clearly see it in the source code!
Now I tried something else:
$titles=$xml->get_elements_by_tagname();
foreach ($titles as $title) {
echo $title->tagname();
}
is working, so it finds childs within the dom. why doesn't it find anything with first_child() ?
I also tried child_nodes():
$node2=$node->child_nodes();
foreach ($node2 as $node3) {
$node3->tagname();
}
also NOT working ("Fatal error: call to undefined function: tagname() ....") so child_nodes() gave null as result. Unbelievable! And I just got results from the very same file!
Would be great if someone knows about this and could help me.
Thanks,
Raik