19.2 Building a Simple XML-Based Application


The standard interface for working with XML is DOM. It offers a simple way to interact with XML documents just as you would do with a tree. In PHP 4.1.1, DOM is still in beta, so we have decided not to go into detail because things can change rapidly. However, to understand the basic concepts of DOM, a simple example is helpful:

 <?php         $doc = new DomDocument;         $node = new DomNode;         $doc = xmldocfile( "file.xml" );         $person = $doc->root();         $nodes = $person->children();         print $nodes[1]->content; ?> 

Recall the XML file you saw before. It contains various nested objects. With the help of this simple PHP script, information about a name is retrieved. First, two objects are created. The first one points to the root element of the document. The second one is used for processing one node of the document. With the help of the xmldocfile function, an XML file is read and assigned to $doc. Then the root of the document is assigned to $person. In the next step, the children of $person are retrieved and stored in an array. This array is used to display data onscreen:

 Dr. med. John Jackson 

As you can see, using DOM is an easy way of retrieving data stored in an XML file. In future versions of PHP, DOM will certainly play a major role, and powerful applications will be written based on this interface.



PHP and PostgreSQL. Advanced Web Programming2002
PHP and PostgreSQL. Advanced Web Programming2002
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 201

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net