Located in File: Program_Root/xml.inc.php
This class offers methods for accessing the nodes of a XML document using the XPath language. You can add or remove nodes, set or modify their content and their attributes. No additional PHP extensions like DOM XML or something similar are required to use these features.
Includehttp://www.phpxml.org/ Latest release of this classhttp://www.w3.org/TR/xpath W3C XPath RecommendationCopyright (c) 2001 Michael P. Mehl. All rights reserved.Michael P. Mehl <mpm@phpxml.org>1.0 (2001-03-08)public| Class Variable Summary |
$nodes
List of all document nodes. Default Value:
|
$ids
List of document node IDs. Default Value:
|
$path
Current document path. Default Value:
|
$position
Current document position. Default Value:
|
$root
Path of the document root. Default Value:
|
$xpath
Current XPath expression. Default Value:
|
$entities
List of entities to be converted. Default Value:
|
$axes
List of supported XPath axes. Default Value:
|
$functions
List of supported XPath functions. Default Value:
|
$operators
List of supported XPath operators. Default Value:
|
| Variable Detail |
This array contains a list of all document nodes saved as an
associative array.
array
private
This array contains a list of all IDs of all document nodes that
are used for counting when adding a new node.
array
private
This variable saves the current path while parsing a XML file and adding
the nodes being read from the file.
string
private
This variable counts the current document position while parsing a XML
file and adding the nodes being read from the file.
int
private
This string contains the full path to the node that acts as the root
node of the whole document.
string
private
This string contains the full XPath expression being parsed currently.
string
private
This array contains a list of entities to be converted when an XPath
expression is evaluated.
array
private
This array contains a list of all valid axes that can be evaluated in an
XPath expression.
array
private
This array contains a list of all valid functions that can be evaluated
in an XPath expression.
array
private
This array contains a list of all valid operators that can be evaluated
in a predicate of an XPath expression. The list is ordered by the
precedence of the operators (lowest precedence first).
array
private| Function Detail |
XML ( [$file = ""] )
Constructor of the class.This constructor initializes the class and, when a filename is given, tries to read and parse the given file.
$file string Path and name of the file to read and parsed.publicMichael P. Mehl <mpm@phpxml.org>load_file()load_file ( $file )
Reads a file and parses the XML data.This method reads the content of a XML file, tries to parse its content and upon success stores the information retrieved from the file into an array.
$file string Path and name of the file to be read and parsed.publicMichael P. Mehl <mpm@phpxml.org>handle_start_element(), handle_end_element(),
handle_character_data()get_file ( [$highlight = array()], [$root = ""], $level )
Generates a XML file with the content of the current document.This method creates a string containing the XML data being read and modified by this class before. This string can be used to save a modified document back to a file or doing other nice things with it.
$highlight array Array containing a list of full document
paths of nodes to be highlighted by ... tags
in the generated XML string.$root string While doing a recursion with this method, this
parameter is used for internal purpose.$level int While doing a recursion with this method, this
parameter is used for internal purpose.publicMichael P. Mehl <mpm@phpxml.org>string The returned string contains well-formed XML data
representing the content of this document.load_file(), evaluate(), get_content()add_node ( $context, $name )
Adds a new node to the XML document.This method adds a new node to the tree of nodes of the XML document being handled by this class. The new node is created according to the parameters passed to this method.
$content string Full path of the parent, to which the new
node should be added as a child.$name string Name of the new node.publicMichael P. Mehl <mpm@phpxml.org>string The string returned by this method will contain the
full document path of the created node.remove_node(), evaluate()remove_node ( $node )
Removes a node from the XML document.This method removes a node from the tree of nodes of the XML document. If the node is a document node, all children of the node and its character data will be removed. If the node is an attribute node, only this attribute will be removed, the node to which the attribute belongs as well as its children will remain unmodified.
$node string Full path of the node to be removed.publicMichael P. Mehl <mpm@phpxml.org>add_node(), evaluate()add_content ( $path, $value )
Add content to a node.This method adds content to a node. If it's an attribute node, then the value of the attribute will be set, otherwise the character data of the node will be set. The content is appended to existing content, so nothing will be overwritten.
$path string Full document path of the node.$value string String containing the content to be added.publicMichael P. Mehl <mpm@phpxml.org>get_content(), evaluate()set_content ( $path, $value )
Set the content of a node.This method sets the content of a node. If it's an attribute node, then the value of the attribute will be set, otherwise the character data of the node will be set. Existing content will be overwritten.
$path string Full document path of the node.$value string String containing the content to be set.publicMichael P. Mehl <mpm@phpxml.org>get_content(), evaluate()get_content ( $path )
Retrieves the content of a node.This method retrieves the content of a node. If it's an attribute node, then the value of the attribute will be retrieved, otherwise it'll be the character data of the node.
$path string Full document path of the node, from which the
content should be retrieved.publicMichael P. Mehl <mpm@phpxml.org>string The returned string contains either the value or the
character data of the node.set_content(), evaluate()add_attributes ( $path, $attributes )
Add attributes to a node.This method adds attributes to a node. Existing attributes will not be overwritten.
$path string Full document path of the node, the attributes
should be added to.$attributes array Associative array containing the new
attributes for the node.publicMichael P. Mehl <mpm@phpxml.org>set_content(), get_content()set_attributes ( $path, $attributes )
Sets the attributes of a node.This method sets the attributes of a node and overwrites all existing attributes by doing this.
$path string Full document path of the node, the attributes
of which should be set.$attributes array Associative array containing the new
attributes for the node.publicMichael P. Mehl <mpm@phpxml.org>set_content(), get_content()get_attributes ( $path )
Retrieves a list of all attributes of a node.This method retrieves a list of all attributes of the node specified in the argument.
$path string Full document path of the node, from which the
list of attributes should be retrieved.publicMichael P. Mehl <mpm@phpxml.org>array The returned associative array contains the all
attributes of the specified node.get_content(), $nodes, $idsget_name ( $path )
Retrieves the name of a document node.This method retrieves the name of document node specified in the argument.
$path string Full document path of the node, from which the
name should be retrieved.publicMichael P. Mehl <mpm@phpxml.org>string The returned array contains the name of the specified
node.get_content(), $nodes, $idsevaluate ( $path, [$context = ""] )
Evaluates an XPath expression.This method tries to evaluate an XPath expression by parsing it. A XML document has to be read before this method is able to work.
$path string XPath expression to be evaluated.$context string Full path of a document node, starting
from which the XPath expression should be evaluated.publicMichael P. Mehl <mpm@phpxml.org>array The returned array contains a list of the full
document paths of all nodes that match the evaluated
XPath expression.$nodes, $idshandle_start_element ( $parser, $name, $attributes )
Handles opening XML tags while parsing.While parsing a XML document for each opening tag this method is called. It'll add the tag found to the tree of document nodes.
$parser int Handler for accessing the current XML parser.$name string Name of the opening tag found in the document.$attributes array Associative array containing a list of
all attributes of the tag found in the document.privateMichael P. Mehl <mpm@phpxml.org>handle_end_element(), handle_character_data(), $nodes, $idshandle_end_element ( $parser, $name )
Handles closing XML tags while parsing.While parsing a XML document for each closing tag this method is called.
$parser int Handler for accessing the current XML parser.$name string Name of the closing tag found in the document.privateMichael P. Mehl <mpm@phpxml.org>handle_start_element(), handle_character_data(), $nodes, $idshandle_character_data ( $parser, $text )
Handles character data while parsing.While parsing a XML document for each character data this method is called. It'll add the character data to the document tree.
$parser int Handler for accessing the current XML parser.$text string Character data found in the document.privateMichael P. Mehl <mpm@phpxml.org>handle_start_element(), handle_end_element(), $nodes, $idssplit_paths ( $expression )
Splits an XPath expression into its different expressions.This method splits an XPath expression. Each expression can consists of list of expression being separated from each other by a | character.
$expression string The complete expression to be splitted
into its different expressions.privateMichael P. Mehl <mpm@phpxml.org>array The array returned from this method contains a list
of all expressions found in the expression passed to this
method as a parameter.evalute()split_steps ( $expression )
Splits an XPath expression into its different steps.This method splits an XPath expression. Each expression can consists of list of steps being separated from each other by a / character.
$expression string The complete expression to be splitted
into its different steps.privateMichael P. Mehl <mpm@phpxml.org>array The array returned from this method contains a list
of all steps found in the expression passed to this
method as a parameter.evalute()get_axis ( $step, $node )
Retrieves axis information from an XPath expression step.This method tries to extract the name of the axis and its node-test from a given step of an XPath expression at a given node.
$step string String containing a step of an XPath expression.$node string Full document path of the node on which the
step is executed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing information
about the axis found in the step.evaluate_step()search_string ( $term, $expression )
Looks for a string within another string.This method looks for a string within another string. Brackets in the string the method is looking through will be respected, which means that only if the string the method is looking for is located outside of brackets, the search will be successful.
$term string String in which the search shall take place.$expression string String that should be searched.privateMichael P. Mehl <mpm@phpxml.org>int This method returns -1 if no string was found, otherwise
the offset at which the string was found.evaluate_step()is_function ( $expression )
Checks for a valid function name.This method check whether an expression contains a valid name of an XPath function.
$expression string Name of the function to be checked.privateMichael P. Mehl <mpm@phpxml.org>boolean This method returns true if the given name is a valid
XPath function name, otherwise false.evaluate()evaluate_step ( $context, $steps )
Evaluates a step of an XPath expression.This method tries to evaluate a step from an XPath expression at a specific context.
$context string Full document path of the context from
which starting the step should be evaluated.$steps array Array containing the remaining steps of the
current XPath expression.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that are the result of evaluating the given XPath step.evaluate()evaluate_function ( $function, $arguments, $node )
Evaluates an XPath functionThis method evaluates a given XPath function with its arguments on a specific node of the document.
$function string Name of the function to be evaluated.$arguments string String containing the arguments being
passed to the function.$node string Full path to the document node on which the
function should be evaluated.privateMichael P. Mehl <mpm@phpxml.org>mixed This method returns the result of the evaluation of
the function. Depending on the function the type of the
return value can be different.evaluate()evaluate_predicate ( $node, $predicate )
Evaluates a predicate on a node.This method tries to evaluate a predicate on a given node.
$node string Full path of the node on which the predicate
should be evaluated.$predicate string String containing the predicate expression
to be evaluated.privateMichael P. Mehl <mpm@phpxml.org>mixed This method is called recursively. The first call should
return a boolean value, whether the node matches the predicate
or not. Any call to the method being made during the recursion
may also return other types for further processing.evaluate()check_predicates ( $nodes, $predicates )
Checks whether a node matches predicates.This method checks whether a list of nodes passed to this method match a given list of predicates.
$nodes array Array of full paths of all nodes to be tested.$predicates array Array of predicates to use.privateMichael P. Mehl <mpm@phpxml.org>array The array returned by this method contains a list of
all nodes matching the given predicates.evaluate_step()check_node_test ( $context, $node_test )
Checks whether a node matches a node-test.This method checks whether a node in the document matches a given node-test.
$context string Full path of the node, which should be tested
for matching the node-test.$node_test string String containing the node-test for the
node.privateMichael P. Mehl <mpm@phpxml.org>boolean This method returns true if the node matches the
node-test, otherwise false.evaluate()handle_axis_child ( $axis, $context )
Handles the XPath child axis.This method handles the XPath child axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_parent ( $axis, $context )
Handles the XPath parent axis.This method handles the XPath parent axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_attribute ( $axis, $context )
Handles the XPath attribute axis.This method handles the XPath attribute axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_self ( $axis, $context )
Handles the XPath self axis.This method handles the XPath self axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_descendant ( $axis, $context )
Handles the XPath descendant axis.This method handles the XPath descendant axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_ancestor ( $axis, $context )
Handles the XPath ancestor axis.This method handles the XPath ancestor axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_namespace ( $axis, $context )
Handles the XPath namespace axis.This method handles the XPath namespace axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_following ( $axis, $context )
Handles the XPath following axis.This method handles the XPath following axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_preceding ( $axis, $context )
Handles the XPath preceding axis.This method handles the XPath preceding axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_following_sibling ( $axis, $context )
Handles the XPath following-sibling axis.This method handles the XPath following-sibling axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_preceding_sibling ( $axis, $context )
Handles the XPath preceding-sibling axis.This method handles the XPath preceding-sibling axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_descendant_or_self ( $axis, $context )
Handles the XPath descendant-or-self axis.This method handles the XPath descendant-or-self axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_axis_ancestor_or_self ( $axis, $context )
Handles the XPath ancestor-or-self axis.This method handles the XPath ancestor-or-self axis.
$axis array Array containing information about the axis.$context string Node from which starting the axis should
be processed.privateMichael P. Mehl <mpm@phpxml.org>array This method returns an array containing all nodes
that were found during the evaluation of the given axis.evaluate()handle_function_last ( $node, $arguments )
Handles the XPath function last.This method handles the XPath function last.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_position ( $node, $arguments )
Handles the XPath function position.This method handles the XPath function position.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_count ( $node, $arguments )
Handles the XPath function count.This method handles the XPath function count.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_id ( $node, $arguments )
Handles the XPath function id.This method handles the XPath function id.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_name ( $node, $arguments )
Handles the XPath function name.This method handles the XPath function name.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_string ( $node, $arguments )
Handles the XPath function string.This method handles the XPath function string.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_concat ( $node, $arguments )
Handles the XPath function concat.This method handles the XPath function concat.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_starts_with ( $node, $arguments )
Handles the XPath function starts-with.This method handles the XPath function starts-with.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_contains ( $node, $arguments )
Handles the XPath function contains.This method handles the XPath function contains.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_substring_before ( $node, $arguments )
Handles the XPath function substring-before.This method handles the XPath function substring-before.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_substring_after ( $node, $arguments )
Handles the XPath function substring-after.This method handles the XPath function substring-after.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_substring ( $node, $arguments )
Handles the XPath function substring.This method handles the XPath function substring.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_string_length ( $node, $arguments )
Handles the XPath function string-length.This method handles the XPath function string-length.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_translate ( $node, $arguments )
Handles the XPath function translate.This method handles the XPath function translate.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_boolean ( $node, $arguments )
Handles the XPath function boolean.This method handles the XPath function boolean.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_not ( $node, $arguments )
Handles the XPath function not.This method handles the XPath function not.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_true ( $node, $arguments )
Handles the XPath function true.This method handles the XPath function true.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_false ( $node, $arguments )
Handles the XPath function false.This method handles the XPath function false.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_lang ( $node, $arguments )
Handles the XPath function lang.This method handles the XPath function lang.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_number ( $node, $arguments )
Handles the XPath function number.This method handles the XPath function number.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_sum ( $node, $arguments )
Handles the XPath function sum.This method handles the XPath function sum.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_floor ( $node, $arguments )
Handles the XPath function floor.This method handles the XPath function floor.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_ceiling ( $node, $arguments )
Handles the XPath function ceiling.This method handles the XPath function ceiling.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_round ( $node, $arguments )
Handles the XPath function round.This method handles the XPath function round.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()handle_function_text ( $node, $arguments )
Handles the XPath function text.This method handles the XPath function text.
$node string Full path of the node on which the function
should be processed.$arguments string String containing the arguments that were
passed to the function.privateMichael P. Mehl <mpm@phpxml.org>mixed Depending on the type of function being processed this
method returns different types.evaluate()prestr ( $string, $delimiter )
Retrieves a substring before a delimiter.This method retrieves everything from a string before a given delimiter, not including the delimiter.
$string string String, from which the substring should be
extracted.$delimiter string String containing the delimiter to use.privateMichael P. Mehl <mpm@phpxml.org>string Substring from the original string before the
delimiter.afterstr()afterstr ( $string, $delimiter )
Retrieves a substring after a delimiter.This method retrieves everything from a string after a given delimiter, not including the delimiter.
$string string String, from which the substring should be
extracted.$delimiter string String containing the delimiter to use.privateMichael P. Mehl <mpm@phpxml.org>string Substring from the original string after the
delimiter.prestr()display_error ( $message )
Displays an error message.This method displays an error messages and stops the execution of the script. This method is called exactly in the same way as the printf function. The first argument contains the message and additional arguments of various types may be passed to this method to be inserted into the message.
$message string Error message to be displayed.privateMichael P. Mehl <mpm@phpxml.org>