I've just started tinkering with XML manipulation with PHP, and i've stumbled into something unexpected. Here's the XML i'm using as a test input:
<list>
<activity1> running </activity1>
<activity2> swimming </activity2>
<activity3> soccer </activity3>
</list>
Now, i was expecting that this PHP code would output 'activity1':
$xmldoc = new DOMDocument();
$xmldoc->load('file.xml');
//the line below would make $root the <list> node
$root = $xmldoc->firstChild;
//the line below would make $cnode the first child
//of the <list> node, which is <activity1>
$cnode = $root->firstChild;
//this should output 'activity1'
echo 'element name: ' . $cnode->nodeName;
Instead, this code outputs #text. I could fix that by inserting a new line in the code, before printing the node name:
$cnode = $cnode->nextSibling;
Now, i would have expected that to print 'activity2' instead, but is printing 'activity1'. What is going on?