Methods summary
public
|
#
__construct( string $data, boolean $auto_trim = false, integer $level = null, boolean $is_clone = false )
Constructor for the xml parser.
Example use:
$xml = new xmlArray(file('data.xml'));
Constructor for the xml parser.
Example use: $xml = new xmlArray(file('data.xml'));
Parameters
- $data
- The xml data or an array of, unless is_clone is true.
- $auto_trim
- Used to automatically trim textual data.
- $level
- The debug level. Specifies whether notices should be generated for missing elements and attributes.
- $is_clone
- default false. If is_clone is true, the xmlArray is cloned from another - used internally only.
|
public
string
|
#
name( )
Get the root element's name.
Example use:
echo $element->name();
Get the root element's name.
Example use: echo $element->name();
Returns
string The root element's name
|
public
string
|
#
fetch( string $path, boolean $get_elements = false )
Get a specified element's value or attribute by path.
Children are parsed for text, but only textual data is returned
unless get_elements is true.
Example use:
$data = $xml->fetch('html/head/title');
Get a specified element's value or attribute by path.
Children are parsed for text, but only textual data is returned
unless get_elements is true.
Example use: $data = $xml->fetch('html/head/title');
Parameters
- $path
- The path to the element to fetch
- $get_elements
- Whether to include elements
Returns
string The value or attribute of the specified element
|
public
xmlArray,
|
#
path( $path, $return_full = false )
Get an element, returns a new xmlArray.
It finds any elements that match the path specified.
It will always return a set if there is more than one of the element
or return_set is true.
Example use:
$element = $xml->path('html/body');
Get an element, returns a new xmlArray.
It finds any elements that match the path specified.
It will always return a set if there is more than one of the element
or return_set is true.
Example use: $element = $xml->path('html/body');
Parameters
- $path
- The path to the element to get
- $return_full
- Whether to return the full result set
Returns
xmlArray, a new xmlArray.
|
public
boolean
|
#
exists( string $path )
Check if an element exists.
Example use,
echo $xml->exists('html/body') ? 'y' : 'n';
Check if an element exists.
Example use, echo $xml->exists('html/body') ? 'y' : 'n';
Parameters
- $path
- The path to the element to get.
Returns
boolean Whether the specified path exists
|
public
integer
|
#
count( string $path )
Count the number of occurrences of a path.
Example use:
echo $xml->count('html/head/meta');
Count the number of occurrences of a path.
Example use: echo $xml->count('html/head/meta');
Parameters
- $path
- The path to search for.
Returns
integer The number of elements the path matches.
|
public
xmlArray[]
|
#
set( $path )
Get an array of xmlArray's matching the specified path.
This differs from ->path(path, true) in that instead of an xmlArray
of elements, an array of xmlArray's is returned for use with foreach.
Example use:
foreach ($xml->set('html/body/p') as $p)
Get an array of xmlArray's matching the specified path.
This differs from ->path(path, true) in that instead of an xmlArray
of elements, an array of xmlArray's is returned for use with foreach.
Example use: foreach ($xml->set('html/body/p') as $p)
Parameters
- $path
- The path to search for.
Returns
|
public
string
|
#
create_xml( string $path = null )
Create an xml file from an xmlArray, the specified path if any.
Example use:
echo $this->create_xml();
Create an xml file from an xmlArray, the specified path if any.
Example use: echo $this->create_xml();
Parameters
- $path
- The path to the element. (optional)
Returns
string Xml-formatted string.
|
public
array
|
#
to_array( string $path = null )
Output the xml in an array form.
Example use:
print_r($xml->to_array());
Output the xml in an array form.
Example use: print_r($xml->to_array());
Parameters
- $path
- The path to output.
Returns
array An array of XML data
|
protected
array
|
#
_parse( string $data )
Parse data into an array. (privately used...)
Parse data into an array. (privately used...)
Parameters
Returns
array The parsed array
|
protected
string
|
#
_xml( array $array, null|integer $indent )
Get a specific element's xml. (privately used...)
Get a specific element's xml. (privately used...)
Parameters
- $array
- An array of element data
- $indent
- How many levels to indent the elements (null = no indent)
Returns
string The formatted XML
|
protected
string|array
|
#
_array( array $array )
Return an element as an array
Return an element as an array
Parameters
Returns
string|array A string with the element's value or an array of element data
|
public
string
|
#
_to_cdata( string $data )
Parse out CDATA tags. (htmlspecialchars them...)
Parse out CDATA tags. (htmlspecialchars them...)
Parameters
- $data
- The data with CDATA tags included
Returns
string The data contained within CDATA tags
|
protected
string
|
#
_from_cdata( string $data )
Turn the CDATAs back to normal text.
Turn the CDATAs back to normal text.
Parameters
- $data
- The data with CDATA tags
Returns
string The transformed data
|
protected
string
|
#
_fetch( array $array )
Given an array, return the text from that array. (recursive and privately used.)
Given an array, return the text from that array. (recursive and privately used.)
Parameters
Returns
string The text from the array
|
protected
string|array
|
#
_path( array $array, string $path, integer $level, boolean $no_error = false )
Get a specific array by path, one level down. (privately used...)
Get a specific array by path, one level down. (privately used...)
Parameters
- $array
- An array of data
- $path
- The path
- $level
- How far deep into the array we should go
- $no_error
- Whether or not to ignore errors
Returns
string|array The specified array (or the contents of said array if there's only one result)
|