*
  • The access to the root node has to be explicit in * IsterXmlSimpleXMLImpl, not implicit as with PHP5. Write * $doc->root->node instead of $doc->node
  • *
  • You cannot acces CDATA using array syntax. Use methods * CDATA() and setCDATA() instead.
  • *
  • You cannot access attributes directly with array syntax. * Always use attributes() to read and setAttribute() to write attributes.
  • *
  • Comments are ignored.
  • *
  • Last and least, this is not as fast as PHP5 SimpleXML--it is pure PHP4.
  • * * * The PHP5 implementation of IsterXmlSimpleXMLImpl will provide a * wrapper or proxy object with the same name to keep compatibility. * * Example: * * :simple.xml: * * * * Tom Foo * Tamara Bar * * * * --- * * // read and write a document * $impl = new IsterXmlSimpleXMLImpl; * $doc = $impl->load_file('simple.xml'); * print $doc->asXML(); * * // access a given node's CDATA * print $doc->root->node->child[0]->CDATA(); // Tom Foo * * // access attributes * $attr = $doc->root->node->child[1]->attributes(); * print $attr['gender']; // f * * // access children * foreach( $doc->root->node->children() as $child ) { * print $child->CDATA(); * } * * // change or add CDATA * $doc->root->node->child[0]->setCDATA('Jane Foo'); * * // change or add attribute * $doc->root->node->child[0]->setAttribute('gender', 'f'); * * * Note: SimpleXML cannot be used to access sophisticated XML doctypes * using datatype ANY (e.g. XHTML). With a DOM implementation you can * handle this. * * * @package xml * @subpackage simplexml * @author Ingo Schramm * @copyright Copyright (c) 2005 Ister.ORG Ingo Schramm */ class IsterXmlSimpleXMLImpl extends IsterObject { /** * @access private */ var $expat; /** * Constructor * */ function IsterXmlSimpleXMLImpl() { parent::IsterObject(); $this->expat = new IsterXmlExpatNonValid; } /** * @param string * @param string currently ignored * @return object SimpleXMLElement */ function load_file($path, $classname = null) { $this->expat->setSourceFile($path); return $this->parse(); } /** * @param string * @param string currently ignored * @return object SimpleXMLElement */ function load_string($string, $classname = null) { $this->expat->setSourceString($string); return $this->parse(); } /** * This method is curently not implemented. * * @param string * @param string currently ignored * @return object SimpleXMLElement */ function import_dom($node, $classname = null) { return $this->log('not implemented', E_USER_WARNING, 'import_dom'); } /** * @access private */ function parse() { $this->expat->parse(); $doc = $this->expat->getDocument(); // create a reference to doc to manipulate internal reference counter // otherwise references won't work with nested arrays // this is pretty a hack! (even works with 4.4.x) // thanks to chat~kaptain524 at neverbox dot com at php.net $r =& $doc; return $doc->toSimpleXML(); } } ?>