class JSimpleXML extends JObject


Located at : UKNOWVA_ROOT/libraries/joomla/utilities/simplexml.php

deprecated

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: Tom Foo Tamara Bar


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

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

Properties

resource $_parser The XML parser
string $_xml The XML document
object $document Document element
array $_stack Current object depth

Methods

__construct(array $options = null) deprecated

Constructor.

string
__toString()

Magic method to convert the object to a string gracefully.

from JObject
mixed
def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

from JObject
mixed
get(string $property, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

from JObject
array
getProperties(boolean $public = true)

Returns an associative array of object properties.

from JObject
string
getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

from JObject
array
getErrors()

Return all errors, if any.

from JObject
mixed
set(string $property, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

from JObject
boolean
setProperties(mixed $properties)

Set the object properties based on a named array/hash.

from JObject
void
setError(string $error)

Add an error message.

from JObject
string
toString() deprecated

No description

from JObject
object
loadString(string $string, string $classname = null) deprecated

Interprets a string of XML into an object

boolean
loadFile(string $path, string $classname = null) deprecated

Interprets an XML file into an object

mixed
importDOM(string $node, string $classname = null) deprecated

Get a JSimpleXMLElement object from a DOM node.

resource
getParser() deprecated

Get the parser

setParser(resource $parser) deprecated

Set the parser

Details

at line 121
JObject __construct(array $options = null) deprecated

deprecated 12.1

Constructor.

Parameters

array $options Options

Return Value

JObject

in JObject at line 56
string __toString()

Magic method to convert the object to a string gracefully.

Return Value

string The classname.

in JObject at line 70
mixed def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

Parameters

string $property The name of the property.
mixed $default The default value.

Return Value

mixed

in JObject at line 88
mixed get(string $property, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

Parameters

string $property The name of the property.
mixed $default The default value.

Return Value

mixed The value of the property.

See also

getProperties()

in JObject at line 107
array getProperties(boolean $public = true)

Returns an associative array of object properties.

Parameters

boolean $public If true, returns only the public properties.

Return Value

array

See also

get()

in JObject at line 133
string getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

Parameters

integer $i Option error index.
boolean $toString Indicates if JError objects should return their error message.

Return Value

string Error message

in JObject at line 165
array getErrors()

Return all errors, if any.

Return Value

array Array of error messages or JErrors.

in JObject at line 180
mixed set(string $property, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

Parameters

string $property The name of the property.
mixed $value The value of the property to set.

Return Value

mixed Previous value of the property.

in JObject at line 198
boolean setProperties(mixed $properties)

Set the object properties based on a named array/hash.

Parameters

mixed $properties Either an associative array or another object.

Return Value

boolean

See also

set()

in JObject at line 222
void setError(string $error)

Add an error message.

Parameters

string $error Error message.

Return Value

void

in JObject at line 235
string toString() deprecated

deprecated 12.1 Use magic method __toString()

Return Value

string

See also

__toString()

at line 162
object loadString(string $string, string $classname = null) deprecated

deprecated 12.1

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.

Parameters

string $string Well-formed XML string data
string $classname currently ignored

Return Value

object JSimpleXMLElement

at line 184
boolean loadFile(string $path, string $classname = null) deprecated

deprecated 12.1

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.

Parameters

string $path Path to XML file containing a well-formed XML document
string $classname currently ignored

Return Value

boolean True if successful, false if file empty

at line 222
mixed importDOM(string $node, string $classname = null) deprecated

deprecated 12.1

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.

Parameters

string $node DOM document
string $classname currently ignored

Return Value

mixed JSimpleXMLElement or false if any errors occur

at line 235
resource getParser() deprecated

deprecated 12.1

Get the parser

Return Value

resource XML parser resource handle

at line 248
setParser(resource $parser) deprecated

deprecated 12.1

Set the parser

Parameters

resource $parser XML parser resource handle