#native_company# #native_desc#
#native_cta#

DOM XML: An Alternative to Expat Page 3

By Matt Dunford
on December 27, 2000

The DomDocument Object Returned By xmltree()

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.
class DomDocument
	properties:
		version
		encoding
		standalone
		name
		content
		type
		attributes
		children
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.
class Attribute
	properties:
		name
		content
	methods:
		name()

class Dtd
	properties:
		extid
		sysid
		name

class Namespace

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:

<?php

# 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.