Xmltree(), a function which I haven't introduced yet, returns a
type of DomDocument object which may give you trouble. This object
has no methods, just properties in place of methods. It has a true
tree structure to it.
It is just as easy to use. For instance, instead of using a
method to get a node's children, just access its 'children' property.
'children' and 'attributes' are both arrays.
The Other Objects
I will list the other objects and their properties and methods just for
reference. We won't be dealing with them in this article.
Using the Objects
The DOM module only has three functions, xmldoc(), xmldocfile(), and
xmltree(). The rest of the time, we will be dealing with the objects.
All functions return DomDocument objects. Here are examples of how
you load xml data into your php script:
# to load xml from a string
# use either of these
$doc = xmldoc( $xmlstr );
$tree = xmltree( $xmlstr );
# to load xml from a file
$doc = xmldocfile( $xmlfile );
All functions will throw an error, if the xml cannot be parsed
correctly. DOM will not validate xml for you. You must find another
way of doing that. Perhaps through another program like xmllint.