February 2013
Intermediate to advanced
538 pages
20h 55m
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 is being parsed, the DOM parser takes an XML document and returns an entire tree of nodes and elements:
$parser=newDOMDocument();$parser->load("books.xml");processNodes($parser->documentElement);functionprocessNodes($node){foreach($node->childNodesas$child){if($child->nodeType==XML_TEXT_NODE){echo$child->nodeValue;
}
else if ($child->nodeType == XML_ELEMENT_NODE) {
processNodes($child);
}
}
}Read now
Unlock full access