Traversing the DOM with PHP’s XPath Classes
The DOM classes discussed in the previous section are more than adequate for most common tasks, but getting used to them can take awhile.
Additionally, for long and complex documents containing a large number of elements and/or levels, progressing from node to node in an iterative manner can often be tedious.You can use a recursive function to simplify the process, but you’ll still have to write a fair amount of code to create and manipulate node collections, which are at different levels of the tree.
It’s precisely to simplify this process that PHP also comes with a couple of XPath classes. XPath, as you may already know, is an addressing mechanism for XML documents, designed to allow XML document ...
Get XML and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.