April 2006
Intermediate to advanced
540 pages
21h 16m
English
The DOM parser provided in PHP is much simpler to use, but what you take out in complexity comes back in memory usage—in spades. Instead of firing events and allowing you to handle the document as it’s being parsed, the DOM parser takes an XML document and returns an entire tree of nodes and elements.
$parser = new DomDocument( );
$rootNode = $parser->load('BookList.xml');
processNodes($rootNode);
function processNodes($node) {
$children = $node->children;
foreach ($children as $child) {
if ($child->nodeType == XML_TEXT_NODE) {
echo $child->noteValue;
}
else if ($child->nodeType == XML_ELEMENT_NODE) {
processNodes($child);
}
}
}Read now
Unlock full access