PHPBuilder - DOM XML: An Alternative to Expat Page 3



RSS Twitter
Articles Php Functions

DOM XML: An Alternative to Expat - Page 3

by: Matt Dunford
|
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.

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Matt Dunford

Comment:



Comment:

(Maximum characters: 1200). You have characters left.