Flourish PHP Unframework

fXML

class, implements ArrayAccess , v1.0.0b8

Provides functionality for XML files

This class is implemented to use the UTF-8 character encoding. Please see http://flourishlib.com/docs/UTF-8 for more information.

Changes:
1.0.0b8Fixed a method signature 8/24/11
1.0.0b7Added a workaround for iconv having issues in MAMP 1.9.4+ 7/26/11
1.0.0b6Updated class to use fCore::startErrorCapture() instead of error_reporting() 8/9/10
1.0.0b5Added the $fix_entities_encoding parameter to __construct() 8/8/10
1.0.0b4Updated the class to automatically add a __ prefix for the default namespace and to use that for attribute and child element access 4/6/10
1.0.0b3Added the $http_timeout parameter to __construct() 9/16/09
1.0.0b2Added instance functionality for reading of XML files 9/1/09
1.0.0bThe initial implementation 1/13/08

Variables

->__custom_prefixes protected

Custom prefix => namespace URI mappings

Type

array

->__dom protected

The dom element for this XML

Type

DOMElement

->__xml protected

The XML string for serialization

Type

string

->__xpath protected

An XPath object for performing xpath lookups

Type

DOMXPath

Static Methods

::encode() public

Encodes content for display in a UTF-8 encoded XML document

Signature

string encode( string $content )

Parameters

string $content The content to encode

Returns

The encoded content

::sendHeader() public

Sets the proper Content-Type HTTP header for a UTF-8 XML file

Signature

void sendHeader( )

Methods

->__construct() public

Create the XML object from a string, fFile or URL

The $default_namespace will be used for any sort of methods calls, member access or array access when the element or attribute name does not include a :.

Signatures

fXML __construct( fFile|string $source, numeric $http_timeout=NULL, boolean $fix_entities_encoding=NULL )

fXML __construct( fFile|string $source, boolean $fix_entities_encoding=NULL )

Parameters

fFile|string $source The source of the XML, either an fFile object, a string of XML, a file path or a URL
numeric $http_timeout The timeout to use in seconds when requesting an XML file from a URL
boolean $fix_entities_encoding This will fix two common XML authoring errors and should only be used when experiencing decoding issues - HTML entities that haven't been encoded as XML, and XML content published in ISO-8859-1 or Windows-1252 encoding without an explicit encoding attribute

Throws

fValidationException
When the source XML is invalid or does not exist

->__get() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Allows access to the text content of a child tag

The child element name ($name) may start with a namespace prefix and a : to indicate what namespace it is part of. A blank namespace prefix (i.e. an element name starting with :) is treated as the XML default namespace.

Signature

fXML|NULL __get( string $name )

Parameters

string $name The child element to retrieve

Returns

The child element requested

->__isset() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

The child element name ($name) may start with a namespace prefix and a : to indicate what namespace it is part of. A blank namespace prefix (i.e. an element name starting with :) is treated as the XML default namespace.

Signature

boolean __isset( string $name )

Parameters

string $name The child element to check - see method description for details about namespaces

Returns

If the child element is set

->__set() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Prevents users from trying to set elements

Signature

void __set( string $name, mixed $value )

Parameters

string $name The element to set
mixed $value The value to set

->__sleep() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

The XML needs to be made into a string before being serialized

Signature

array __sleep( )

Returns

The members to serialize

->__toString() public

Gets the string inside the root XML element

Signature

string __toString( )

Returns

The text inside the root element

->__unset() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Prevents users from trying to unset elements

Signature

void __unset( string $name )

Parameters

string $name The element to unset

->__wakeup() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

The XML needs to be made into a DOMElement when woken up

Signature

void __wakeup( )

->addCustomPrefix() public

Adds a custom namespace prefix to full namespace mapping

This namespace prefix will be valid for any operation on this object, including calls to xpath().

Signature

void addCustomPrefix( string $ns_prefix, string $namespace )

Parameters

string $ns_prefix The custom namespace prefix
string $namespace The full namespace it maps to

->getName() public

Returns the name of the current element

Signature

string getName( )

Returns

The name of the current element

->getNamespace() public

Returns the namespace of the current element

Signature

string getNamespace( )

Returns

The namespace of the current element

->getPrefix() public

Returns the namespace prefix of the current element

Signature

string getPrefix( )

Returns

The namespace prefix of the current element

->getText() public

Returns the string text of the current element

Signature

string getText( )

Returns

The string text of the current element

->offsetExists() internal public implements ArrayAccess

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Provides functionality for isset() and empty() (required by arrayaccess interface)

Offsets refers to an attribute name. Attribute may start with a namespace prefix and a : to indicate what namespace the attribute is part of. A blank namespace prefix (i.e. an offset starting with :) is treated as the XML default namespace.

Signature

boolean offsetExists( string $offset )

Parameters

string $offset The offset to check

Returns

If the offset exists

->offsetGet() internal public implements ArrayAccess

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Provides functionality for get [index] syntax (required by ArrayAccess interface)

Offsets refers to an attribute name. Attribute may start with a namespace prefix and a : to indicate what namespace the attribute is part of. A blank namespace prefix (i.e. an offset starting with :) is treated as the XML default namespace.

Signature

string offsetGet( string $offset )

Parameters

string $offset The attribute to retrieve the value for

Returns

The value of the offset

->offsetSet() internal public implements ArrayAccess

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Required by ArrayAccess interface

Signature

void offsetSet( integer|string $offset, $value )

Parameters

integer|string $offset The offset to set
$value

->offsetUnset() internal public implements ArrayAccess

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Required by ArrayAccess interface

Signature

void offsetUnset( integer|string $offset )

Parameters

integer|string $offset The offset to unset

->query() protected

Performs an XPath query on the current element, returning the raw results

Signature

array query( string $path )

Parameters

string $path The XPath path to query

Returns

The matching elements

->toXML() public

Returns a well-formed XML string from the current element

Signature

string toXML( )

Returns

The XML

->xpath() public

Executes an XPath query on the current element, returning an array of matching elements

Signature

array|string|fXML xpath( string $path, boolean $first_only=FALSE )

Parameters

string $path The XPath path to query
boolean $first_only If only the first match should be returned

Returns

An array of matching elements, or a string or fXML object if $first_only is TRUE