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. Nevertheless, it is an easy way to deal with XML data, especially for read only access.
Because it's not possible to use the PHP5 ArrayIterator interface with PHP4 there are some differences between this implementation and that of PHP5:
- The access to the root node has to be explicit in JSimpleXML, not implicit as with PHP5. Write $xml->document->node instead of $xml->node
- You cannot acces CDATA using array syntax. Use the method data() instead
- You cannot access attributes directly with array syntax. use attributes() to read them.
- Comments are ignored.
- Last and least, this is not as fast as PHP5 SimpleXML--it is pure PHP4.
Example:
- :simple.xml:
- <?xml version="1.0" encoding="utf-8" standalon="yes"?>
- <document>
- <node>
- <child gender="m">Tom Foo</child>
- <child gender="f">Tamara Bar</child>
- <node>
- </document>
- ---
- // read and write a document
- $xml = new JSimpleXML;
- $xml->loadFile('simple.xml');
- print $xml->asXML();
- // access a given node's CDATA
- print $xml->root->node->child[0]->data(); // Tom Foo
- // access attributes
- $attr = $xml->root->node->child[1]->attributes();
- print $attr['gender']; // f
- // access children
- foreach( $xml->root->node->children() as $child ) {
- print $child->data();
- }
Note: JSimpleXML cannot be used to access sophisticated XML doctypes using datatype ANY (e.g. XHTML). With a DOM implementation you can handle this.
Located in /joomla/utilities/simplexml.php (line 84)
JObject (Subpackage Base) JSimpleXML (Subpackage Utilities)
Constructor.
- $options
- JObject::__construct()
- Class constructor, overridden in descendant classes.
Get a JSimpleXMLElement object from a DOM node.
This function takes a node of a DOM document and makes it into a JSimpleXML node. This new object can then be used as a native JSimpleXML element. If any errors occur, it returns FALSE.
- string $node: DOM document
- string $classname: currently ignored
Interprets an XML file into an object
This function will convert the well-formed XML document in the file specified by filename to an object of class JSimpleXMLElement. If any errors occur during file access or interpretation, the function returns FALSE.
- string $path: Path to xml file containing a well-formed XML document
- string $classname: currently ignored
Interprets a string of XML into an object
This function will take the well-formed xml string data and return an object of class JSimpleXMLElement with properties containing the data held within the xml document. If any errors occur, it returns FALSE.
- string $string: Well-formed xml string data
- string $classname: currently ignored
Set the parser
- resource $parser: XML parser resource handle
Handler function for the character data within a tag
- resource $parser
- string $data
Handler function for the end of a tag
- resource $parser
- string $name
Gets the reference to the current direct parent
Handles an XML parsing error
- int $code: XML Error Code
- int $line: Line on which the error happened
- int $col: Column on which the error happened
Start parsing an XML document
Parses an XML document. The handlers for the configured events are called as many times as necessary.
- $xml $data: string data to parse
Handler function for the start of a tag
- resource $parser
- string $name
- array $attrs
Inherited Methods
Inherited From JObject
JObject::JObject()
JObject::__construct()
JObject::get()
JObject::getPublicProperties()
JObject::set()
JObject::toString()
Documentation generated on Mon, 05 Mar 2007 21:25:20 +0000 by phpDocumentor 1.3.1