Traversing the DOM with PHP’s DOM Classes
Because PHP’s DOM parser works by creating standard objects to represent XML structures, an understanding of these objects and their capabilities is essential to using this technique effectively. This section examines the classes that form the blueprint for these objects in greater detail.
DomDocument Class
A DomDocument object is typically the first object created by the DOM parser when it completes parsing an XML document. It may be created by a call to xmldoc():
$doc = xmldoc("<?xml version='1.0'?><element>potassium</element>");
Or, if your XML data is in a file (rather than a string), you can use the xmldocfile() function to create a DomDocument object:
$doc = xmldocfile("element.xml");
Treading ... |
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.