This chapter isn’t a comprehensive look at every advanced feature in the DOM library. The DOM library is enormous. We are going to examine DOM’s approach to some advanced XML features. A more comprehensive reference to the DOM library can be found in Appendix B.
We’ve discussed XPath several times, but DOM is where it really becomes essential.
Let’s start by loading our library file.
$DOMdoc = new DOMDocument(); $DOMdoc->load('library.xml');
To perform XPath queries with DOM, we must create an XPath object using a DOMDocument object.
$xpath = new DOMXpath($DOMdoc);
Remember our query for all book nodes from Chapter 2? We can retrieve all book nodes with the absolute XPath expression