[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/utilities/ -> simplexml.php (summary)

(no description)

Copyright: Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
License: GNU/GPL, see LICENSE.php
Version: $Id: simplexml.php 14401 2010-01-26 14:10:00Z louis $
File Size: 669 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

JSimpleXML:: (12 methods):
  __construct()
  loadString()
  loadFile()
  importDOM()
  getParser()
  setParser()
  _parse()
  _handleError()
  _getStackLocation()
  _startElement()
  _endElement()
  _characterData()

JSimpleXMLElement:: (14 methods):
  __construct()
  name()
  attributes()
  data()
  setData()
  children()
  level()
  addAttribute()
  removeAttribute()
  addChild()
  removeChild()
  getElementByPath()
  map()
  toString()


Class: JSimpleXML  - X-Ref

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:

<ul>
<li>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</li>
<li>You cannot acces CDATA using array syntax. Use the method data() instead</li>
<li>You cannot access attributes directly with array syntax. use attributes()
to read them.</li>
<li>Comments are ignored.</li>
<li>Last and least, this is not as fast as PHP5 SimpleXML--it is pure PHP4.</li>
</ul>

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

---

// read and write a document
$xml = new JSimpleXML;
$xml->loadFile('simple.xml');
print $xml->document->toString();

// 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();
}
</code>

Note: JSimpleXML cannot be used to access sophisticated XML doctypes
using datatype ANY (e.g. XHTML). With a DOM implementation you can
handle this.

__construct($options = null)   X-Ref
Constructor.


loadString($string, $classname = null)   X-Ref
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.

param: string  Well-formed xml string data
param: string  currently ignored
return: object JSimpleXMLElement

loadFile($path, $classname = null)   X-Ref
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.

param: string  Path to xml file containing a well-formed XML document
param: string  currently ignored
return: boolean True if successful, false if file empty

importDOM($node, $classname = null)   X-Ref
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.

param: string    DOM  document
param: string       currently ignored
return: object     JSimpleXMLElement

getParser()   X-Ref
Get the parser

return: resource XML parser resource handle

setParser($parser)   X-Ref
Set the parser

param: resource    XML parser resource handle

_parse($data = '')   X-Ref
Start parsing an XML document

Parses an XML document. The handlers for the configured events are called as many times as necessary.

param: $xml     string     data to parse

_handleError($code, $line, $col)   X-Ref
Handles an XML parsing error

param: int $code XML Error Code
param: int $line Line on which the error happened
param: int $col Column on which the error happened

_getStackLocation()   X-Ref
Gets the reference to the current direct parent

return: object

_startElement($parser, $name, $attrs = array()   X-Ref
Handler function for the start of a tag

param: resource $parser
param: string $name
param: array $attrs

_endElement($parser, $name)   X-Ref
Handler function for the end of a tag

param: resource $parser
param: string $name

_characterData($parser, $data)   X-Ref
Handler function for the character data within a tag

param: resource $parser
param: string $data

Class: JSimpleXMLElement  - X-Ref

SimpleXML Element

This object stores all of the direct children of itself in the $children array.
They are also stored by type as arrays. So, if, for example, this tag had 2 <font>
tags as children, there would be a class member called $font created as an array.
$font[0] would be the first font tag, and $font[1] would be the second.

To loop through all of the direct children of this object, the $children member
should be used.

To loop through all of the direct children of a specific tag for this object, it
is probably easier to use the arrays of the specific tag names, as explained above.

__construct($name, $attrs = array()   X-Ref
Constructor, sets up all the default values

param: string $name
param: array $attrs
param: int $parents
return: JSimpleXMLElement

name()   X-Ref
Get the name of the element

return: string

attributes($attribute = null)   X-Ref
Get the an attribute of the element

param: string $attribute     The name of the attribute
return: mixed If an attribute is given will return the attribute if it exist.

data()   X-Ref
Get the data of the element

return: string

setData($data)   X-Ref
Set the data of the element

param: string $data
return: string

children()   X-Ref
Get the children of the element

return: array

level()   X-Ref
Get the level of the element

return: int

addAttribute($name, $value)   X-Ref
Adds an attribute to the element

param: string $name
param: array  $attrs

removeAttribute($name)   X-Ref
Removes an attribute from the element

param: string $name

addChild($name, $attrs = array()   X-Ref
Adds a direct child to the element

param: string $name
param: array  $attrs
param: int      $level
return: JSimpleXMLElement     The added child object

removeChild(&$child)   X-Ref
No description

getElementByPath($path)   X-Ref
Get an element in the document by / separated path

param: string    $path    The / separated path to the element
return: object    JSimpleXMLElement

map($callback, $args=array()   X-Ref
traverses the tree calling the $callback( JSimpleXMLElement
$this, mixed $args=array() ) function with each JSimpleXMLElement.

param: string $callback function name
param: array $args

toString($whitespace=true)   X-Ref
Return a well-formed XML string based on SimpleXML element

return: string



Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1