If you want to keep memory usage light on a large XML input, then the streaming XML parser may be a better choice.
I definitely agree, although I took the lazy approach and illustrate my point using what I know: DOMDocument.
Note: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
Although the actual problem here seems to be that it only retrieves elements of d, not nodes. Bug? Since I'm not familiar with SimpleXML there may be some other method of accessing child nodes, rather than child elements, but I failed finding one with a quick glance in the manual.
I'd have expected 3 iterations with output for
$d-> first child node (TextNode)
$d-> second child (c element)
$d-> last child node (TextNode)
Similarly, assigning not $xml->d->children to $data, but rather $xml->d ought to assign the d element, on which an echo should produce its node value (which is all the text nodes contained in d directly as well as all the text nodes of d's child elements).
Originally Posted by s0me0ne
Here is my sample XML file, as you can see the D node doesn't have any text and neither does the C element...
If you're talking about the results using simpleXML in your example, then I agree. But if you're talking about thow things really are, then this should be corrected to:
The D node has 3 child nodes: A newline (LF) text node, followed by an empty c element, followed by a "bird food\n" text node.
And, demonstrating this using Dom
$xml = new DOMDocument('1.0');