xml 
[ doc home ] [ class tree: xml ] [ index: xml ] [ all elements ]

Class: IsterXmlSimpleXMLImpl

Source Location: /IsterXmlSimpleXMLImpl.php

Class Overview

IsterObject
   |
   --IsterXmlSimpleXMLImpl

This class represents a SimpleXML implementation.


Author(s): Ingo Schramm   

Copyright: Copyright (c) 2005 Ister.ORG Ingo Schramm

Methods


Inherited Constants

Inherited Variables

Inherited Methods

Class: IsterObject

IsterObject::IsterObject()
Constructor
IsterObject::abstractMethodError()
Report attempt to call an abstract method.
IsterObject::addLogger()
Add an IsterLogger to process log messages.
IsterObject::deleteLogger()
Delete an already registered IsterLogger.
IsterObject::getLoggerNames()
Fetch the names of all currently registered IsterLoggers.
IsterObject::getMem()
Return maximum amount of memory an application has allocated at this point.
IsterObject::log()
Trigger a log message.
IsterObject::passPHPmessage()
Catch PHP E_WARNING and E_NOTICE messages.
IsterObject::serialize()
Serialize the object.
IsterObject::setLogLocal()
Set logging local for the current object.
IsterObject::setupLogger()
Setup a logger.
IsterObject::triggerError()
Alias for log();
IsterObject::unserialize()
Unserialize the object.
IsterObject::__sleep()
Executed prior to serialize().
IsterObject::__wakeup()
Executed prior to unserialize().

Class Details

This class represents a SimpleXML implementation.

The XML Parser extension (expat) is required to use IsterXmlSimpleXMLImpl.

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 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:

  1. :simple.xml:
  2. <?xml version="1.0" encoding="utf-8" standalon="yes"?>
  3. <root>
  4. <node>
  5. <child gender="m">Tom Foo</child>
  6. <child gender="f">Tamara Bar</child>
  7. <node>
  8. </root>
  9.  
  10. ---
  11.  
  12. // read and write a document
  13. $impl = new IsterXmlSimpleXMLImpl;
  14. $doc = $impl->load_file('simple.xml');
  15. print $doc->asXML();
  16.  
  17. // access a given node's CDATA
  18. print $doc->root->node->child[0]->CDATA(); // Tom Foo
  19.  
  20. // access attributes
  21. $attr = $doc->root->node->child[1]->attributes();
  22. print $attr['gender']; // f
  23.  
  24. // access children
  25. foreach( $doc->root->node->children() as $child ) {
  26. print $child->CDATA();
  27. }
  28.  
  29. // change or add CDATA
  30. $doc->root->node->child[0]->setCDATA('Jane Foo');
  31.  
  32. // change or add attribute
  33. $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.


copyright:  Copyright (c) 2005 Ister.ORG Ingo Schramm
author:  Ingo Schramm


[ Top ]


Class Methods


constructor IsterXmlSimpleXMLImpl

IsterXmlSimpleXMLImpl IsterXmlSimpleXMLImpl( )

Constructor

[ Top ]

method import_dom

object SimpleXMLElement import_dom( string $node, [string $classname = null])

This method is curently not implemented.

Parameters:

string   $node  
string   $classname   currently ignored

[ Top ]

method load_file

object SimpleXMLElement load_file( string $path, [string $classname = null])

Parameters:

string   $path  
string   $classname   currently ignored

[ Top ]

method load_string

object SimpleXMLElement load_string( string $string, [string $classname = null])

Parameters:

string   $string  
string   $classname   currently ignored

[ Top ]


Documentation generated on Tue, 20 Dec 2005 11:21:47 +0100 by phpDocumentor 1.3.0RC4