references:joomla.framework:utilities:jsimplexmlTable of Contents
JSimpleXML
SimpleXML implementation.
The XML Parser extension (expat) is required to use JSimpleXML. The class provides a pure PHP4 implementation of the PHP5 interface SimpleXML. As with PHP5’s SimpleXML it is what it says: simple. Because it’s not possible to use the PHP5 ArrayIterator interface with PHP4 there are some differences between this implementation and that of PHP5:
Note: JSimpleXML cannot be used to access sophisticated XML doctypes using datatype ANY (e.g. XHTML). With a DOM implementation you can handle this. Methods
Related ClassesExamplesXML source document (simple.xml) <?xml version=""1.0" encoding="utf-8" standalone="yes"?> <document> <node> <child gender="m">Tom Foo</child> <child gender="f">Tamara Bar</child> <node> </document> Example 1: return XML source // read and write a document $xml = new JSimpleXML; $xml->loadFile('simple.xml'); echo $xml->toString(); Will return the XML source of ‘simple.xml’ as depicted above. Example 2:accessing node data // access a given node's CDATA echo 'Name:', $xml->root->node->child[0]->data(); // access attributes $attr = $xml->root->node->child[1]->attributes(); echo 'Gender: ', ($attr['gender'] == 'f') ? 'female' : 'male'; Will output: Name: Tom Foo Gender: male Example 3:Loop through child nodes // access children foreach( $xml->root->node->children() as $child ) { echo $child->data(); } Will output: Tom Foo Tamara Bar Discussion |


