Class XPathEngine

Description

**********************************************************************************************

=============================================================================================== X P a t h E n g i n e - Class =============================================================================================== **********************************************************************************************

Located in /web/phpsysinfo/includes/XPath.class.php (line 854)

XPathBase
   |
   --XPathEngine
Direct descendents
Class Description
 class XPath **********************************************************************************************
Variable Summary
Method Summary
 XPathEngine XPathEngine ([$userXmlOptions $userXmlOptions = array()])
 (&array) &cloneNode ($node $node, [ $recursive = FALSE])
 (mixed) decodeEntities ($encodedData $encodedData, [$reverse $reverse = FALSE])
 (bool) equalNodes ($node1 $node1, $node2 $node2)
 void evaluate ( $xPathQuery, [ $baseXPath = ''])
 (mixed) exportAsHtml ([$absoluteXPath $absoluteXPath = ''], [$hilighXpathList $hilightXpathList = array()])
 (mixed) exportAsXml ([$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL])
 (string) exportToFile ($fileName $fileName, [$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL])
 (array) &getNode ([$absoluteXPath $absoluteXPath = ''])
 (string) getNodePath ($node $node)
 (string) getParentXPath ($childPath $absoluteXPath)
 (mixed) getProperties ([$param $param = NULL])
 (bool) hasChildNodes ($absoluteXPath $absoluteXPath)
 (bool) importFromFile ($fileName $fileName)
 (bool) importFromString ($xmlString $xmlString, [$absoluteParentPath $absoluteParentPath = ''])
 (mixed) match ($xPathQuery $xPathQuery, [$baseXPath $baseXPath = ''])
 (bool) reindexNodeTree ()
 void reset ()
 void setCaseFolding ([$onOff $onOff = TRUE])
 void setSkipWhiteSpaces ([$onOff $onOff = TRUE])
 void setXmlOption ($optionID $optionID, $value $value)
 void setXmlOptions ([$userXmlOptions $userXmlOptions = array()])
 (&string) &wholeText ($absoluteXPath $absoluteXPath, [$textPartNr $textPartNr = NULL])
 (mixed) _addLiteral ($string $string)
 (mixed) _asLiteral ($string $string)
 (boolean) _checkNodeTest ($contextPath $contextPath, $nodeTest $nodeTest)
 (array) _checkPredicates ($xPathSet $xPathSet, $predicates $predicates)
 (mixed) _evaluateExpr ($xPathQuery $xPathQuery, $context $context)
 (mixed) _evaluateFunction ($function $function, $arguments $arguments, $context $context)
 (mixed) _evaluateOperator ($left $left, $right $operator, $operator $right, $operatorType $operatorType, $context $context)
 (mixed) _evaluatePathExpr ($PathExpr $PathExpr, $context $context)
 (string) _evaluatePrimaryExpr ($xPathQuery $xPathQuery, $context $context, $results &$result)
 (array) _evaluateStep ($steps $steps, $context $context)
 (mixed) _export ([$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL], [$hilightXpath $hilightXpathList = ''])
 void _generate_ids ()
 (array) _getAxis ($step $step)
 (array) _GetOperator ($xPathQuery $xPathQuery)
 (array) _handleAxis_ancestor ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_ancestor_or_self ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_attribute ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_child ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_descendant ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_descendant_or_self ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_following ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_following_sibling ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_namespace ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_parent ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_preceding ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_preceding_sibling ($axis $axis, $contextPath $contextPath)
 (array) _handleAxis_self ($axis $axis, $contextPath $contextPath)
 void _handleCharacterData ($parser $parser, $text $text)
 void _handleDefaultData ($parser $parser, $text $text)
 void _handleEndElement ($parser $parser, $name $name)
 (mixed) _handleFunction_boolean ($arguments $arguments, $context $context)
 (mixed) _handleFunction_ceiling ($arguments $arguments, $context $context)
 (mixed) _handleFunction_concat ($arguments $arguments, $context $context)
 (mixed) _handleFunction_contains ($arguments $arguments, $context $context)
 (mixed) _handleFunction_count ($arguments $arguments, $context $context)
 (mixed) _handleFunction_false ($arguments $arguments, $context $context)
 (mixed) _handleFunction_floor ($arguments $arguments, $context $context)
 (mixed) _handleFunction_generate_id ($arguments $arguments, $context $context)
 (mixed) _handleFunction_id ($arguments $arguments, $context $context)
 (mixed) _handleFunction_lang ($arguments $arguments, $context $context)
 (mixed) _handleFunction_last ($arguments $arguments, $context $context)
 (mixed) _handleFunction_name ($arguments $arguments, $context $context)
 (stri)g _handleFunction_normalize_space ($arguments $arguments, $context $context)
 (mixed) _handleFunction_not ($arguments $arguments, $context $context)
 (mixed) _handleFunction_number ($arguments $arguments, $context $context)
 (mixed) _handleFunction_position ($arguments $arguments, $context $context)
 (mixed) _handleFunction_round ($arguments $arguments, $context $context)
 (mixed) _handleFunction_starts_with ($arguments $arguments, $context $context)
 (mixed) _handleFunction_string ($arguments $arguments, $context $context)
 (mixed) _handleFunction_string_length ($arguments $arguments, $context $context)
 (mixed) _handleFunction_substring ($arguments $arguments, $context $context)
 (mixed) _handleFunction_substring_after ($arguments $arguments, $context $context)
 (mixed) _handleFunction_substring_before ($arguments $arguments, $context $context)
 (mixed) _handleFunction_sum ($arguments $arguments, $context $context)
 (mixed) _handleFunction_translate ($arguments $arguments, $context $context)
 (mixed) _handleFunction_true ($arguments $arguments, $context $context)
 (mixed) _handleFunction_x_lower ($arguments $arguments, $context $context)
 (mixed) _handleFunction_x_upper ($arguments $arguments, $context $context)
 void _handlePI ($parser $parser, $target $target, $data $data)
 void _handleStartElement ($parser $parser, $name $nodeName, $attributes $attributes)
 (bool) _internalAppendChild ($stackParentIndex $stackParentIndex, $nodeName $nodeName)
 (string) _InternalExport ($node $node)
 (bool) _recursiveReindexNodeTree ($absoluteParentPath $absoluteParentPath)
 (string) _removeLiterals ($xPathQuery $xPathQuery)
 (array) _sortByDocOrder ($xPathSet $xPathSet)
 (string) _stringValue ($node $node)
 (string) _translateAmpersand ($xmlSource $xmlSource, [ $reverse = FALSE])
Variables
mixed $axes = array ( 'ancestor', 'ancestor_or_self', 'attribute', 'child', 'descendant',
'descendant_or_self', 'following', 'following_sibling',
'namespace', 'parent', 'preceding', 'preceding_sibling', 'self'
)
(line 865)
mixed $axPathLiterals = array() (line 896)
mixed $emptyNode = array(
'name' => '', // The tag name. E.g. In <FOO bar="aaa"/> it would be 'FOO'
'attributes' => array(),// The attributes of the tag E.g. In <FOO bar="aaa"/> it would be array('bar'=>'aaa')
'childNodes'=>array(),// Array of pointers to child nodes.
'textParts'=>array(),// Array of text parts between the cilderen E.g. <FOO>aa<A>bb<B/>cc</A>dd</FOO> -> array('aa','bb','cc','dd')
'parentNode'=>NULL,// Pointer to parent node or NULL if this node is the 'super root'
//-- *!* Following vars are set by the indexer and is for optimisation only *!*
'depth'=>0,// The tag depth (or tree level) starting with the root tag at 0.
'pos'=>0,// Is the zero-based position this node has in the parents 'childNodes'-list.
'contextPos'=>1,// Is the one-based position this node has by counting the siblings tags (tags with same name)
'xpath'=>''// Is the abs. XPath to this node.
)
(line 901)
mixed $errorStrings = array(
'AbsoluteXPathRequired' => "The supplied xPath '%s' does not *uniquely* describe a node in the xml document.",
'NoNodeMatch' => "The supplied xPath-query '%s' does not match *any* node in the xml document.",
'RootNodeAlreadyExists' => "An xml document may have only one root node."
)
(line 927)
mixed $functions = array ( 'last', 'position', 'count', 'id', 'name',
'string', 'concat', 'starts_with', 'contains', 'substring_before',
'substring_after', 'substring', 'string_length', 'normalize_space', 'translate',
'boolean', 'not', 'true', 'false', 'lang', 'number', 'sum', 'floor',
'ceiling', 'round', 'x_lower', 'x_upper', 'generate_id' )
(line 881)
mixed $nodeIndex = array() (line 899)
mixed $nodeRoot = array() (line 900)
mixed $nodeStack = array() (line 917)
mixed $operators = array( ' or ', ' and ', '=', '!=', '<=', '<', '>=', '>',
'+', '-', '*', ' div ', ' mod ', ' | ')
(line 892)
mixed $parsedTextLocation = '' (line 922)
mixed $parseOptions = array() (line 921)
mixed $parseSkipWhiteCache = 0 (line 924)
mixed $parseStackIndex = 0 (line 918)
mixed $parsInCData = 0 (line 923)
mixed $_indexIsDirty = FALSE (line 913)

Inherited Variables

Inherited from XPathBase

XPathBase::$aDebugFunctions
XPathBase::$aDebugOpenLinks
XPathBase::$bClassProfiling
XPathBase::$bDebugXmlParse
XPathBase::$iDebugNextLinkNumber
XPathBase::$_lastError
Methods
Constructor XPathEngine (line 950)

Constructor

Optionally you may call this constructor with the XML-filename to parse and the XML option vector. Each of the entries in the option vector will be passed to xml_parser_set_option().

A option vector sample: $xmlOpt = array(XML_OPTION_CASE_FOLDING => FALSE, XML_OPTION_SKIP_WHITE => TRUE);

XPathEngine XPathEngine ([$userXmlOptions $userXmlOptions = array()])
  • $userXmlOptions $userXmlOptions: (array) (optional) Vector of (<optionID>=><value>, <optionID>=><value>, ...). See PHP's xml_parser_set_option() docu for a list of possible options.
cloneNode (line 2293)

Clone a node and it's child nodes.

NOTE: If the node has children you *MUST* use the reference operator! E.g. $clonedNode =& cloneNode($node); Otherwise the children will not point back to the parent, they will point back to your temporary variable instead.

  • return: A node and it's child nodes.
(&array) &cloneNode ($node $node, [ $recursive = FALSE])
  • $node $node: (mixed) Either a node (hash array) or an abs. Xpath to a node in the current doc
  • $recursive
decodeEntities (line 5037)

Decodes the character set entities in the given string.

This function is given for convenience, as all text strings or attributes are going to come back to you with their entities still encoded. You can use this function to remove these entites.

It makes use of the get_html_translation_table(HTML_ENTITIES) php library call, so is limited in the same ways. At the time of writing this seemed be restricted to iso-8859-1

### Provide an option that will do this by default.

  • return: The string or array returned with entities decoded.
(mixed) decodeEntities ($encodedData $encodedData, [$reverse $reverse = FALSE])
  • $encodedData $encodedData: (mixed) The string or array that has entities you would like to remove
  • $reverse $reverse: (bool) If TRUE entities will be encoded rather than decoded, ie < to &lt; rather than &lt; to <.
equalNodes (line 5077)

Compare two nodes to see if they are equal (point to the same node in the doc)

2 nodes are considered equal if the absolute XPath is equal.

  • return: TRUE if equal (see text above), FALSE if not (and on error).
(bool) equalNodes ($node1 $node1, $node2 $node2)
  • $node1 $node1: (mixed) Either an absolute XPath to an node OR a real tree-node (hash-array)
  • $node2 $node2: (mixed) Either an absolute XPath to an node OR a real tree-node (hash-array)
evaluate (line 2432)

Alias for the match function

void evaluate ( $xPathQuery, [ $baseXPath = ''])
  • $xPathQuery
  • $baseXPath
exportAsHtml (line 1225)

Returns the containing XML as marked up HTML with specified nodes hi-lighted

  • return: The Xml document marked up as HTML so that it can be viewed in a browser, including any XML headers. FALSE on error.
  • see: XPathEngine::_export()
(mixed) exportAsHtml ([$absoluteXPath $absoluteXPath = ''], [$hilighXpathList $hilightXpathList = array()])
  • $absoluteXPath $absoluteXPath: (string) The address of the node you would like to export. If empty the whole document will be exported.
  • $hilighXpathList $hilightXpathList: (array) A list of nodes that you would like to highlight
exportAsXml (line 1245)

Given a context this function returns the containing XML

  • return: The Xml fragment/document, suitable for writing out to an .xml file or as part of a larger xml file, or FALSE on error.
  • see: XPathEngine::_export()
(mixed) exportAsXml ([$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL])
  • $absoluteXPath $absoluteXPath: (string) The address of the node you would like to export. If empty the whole document will be exported.
  • $xmlHeader $xmlHeader: (array) The string that you would like to appear before the XML content. ie before the <root></root>. If you do not specify this argument, the xmlHeader that was found in the parsed xml file will be used instead.
exportToFile (line 1265)

Generates a XML string with the content of the current document and writes it to a file.

Per default includes a <?xml ...> tag at the start of the data too.

(string) exportToFile ($fileName $fileName, [$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL])
  • $fileName $fileName: (string)
  • $absoluteXPath $absoluteXPath: (string) The path to the parent node you want(see text above)
  • $xmlHeader $xmlHeader: (array) The string that you would like to appear before the XML content. ie before the <root></root>. If you do not specify this argument, the xmlHeader that was found in the parsed xml file will be used instead.
getNode (line 1079)

Get the node defined by the $absoluteXPath.

  • return: The node, or FALSE if the node wasn't found.
(array) &getNode ([$absoluteXPath $absoluteXPath = ''])
  • $absoluteXPath $absoluteXPath: (string) (optional, default is 'super-root') xpath to the node.
getNodePath (line 5089)

Get the absolute XPath of a node that is in a document tree.

  • return: The string path to the node or FALSE on error.
(string) getNodePath ($node $node)
  • $node $node: (array) A real tree-node (hash-array)
getParentXPath (line 5116)

Retrieves the absolute parent XPath query.

The parents stored in the tree are only relative parents...but all the parent information is stored in the XPath query itself...so instead we use a function to extract the parent from the absolute Xpath query

  • return: returns the absolute XPath of the parent
(string) getParentXPath ($childPath $absoluteXPath)
  • $childPath $absoluteXPath: (string) String containing an absolute XPath query
getProperties (line 996)

Returns the property/ies you want.

if $param is not given, all properties will be returned in a hash.

  • return: string OR hash of all params, or NULL on an unknown parameter.
(mixed) getProperties ([$param $param = NULL])
  • $param $param: (string) the property you want the value of, or NULL for all the properties
hasChildNodes (line 5131)

Returns TRUE if the given node has child nodes below it

  • return: TRUE if this node exists and has a child, FALSE otherwise
(bool) hasChildNodes ($absoluteXPath $absoluteXPath)
  • $absoluteXPath $absoluteXPath: (string) full path of the potential parent node
importFromFile (line 1659)

Reads a file or URL and parses the XML data.

Parse the XML source and (upon success) store the information into an internal structure.

(bool) importFromFile ($fileName $fileName)
  • $fileName $fileName: (string) Path and name (or URL) of the file to be read and parsed.
importFromString (line 1724)

Reads a string and parses the XML data.

Parse the XML source and (upon success) store the information into an internal structure. If a parent xpath is given this means that XML data is to be *appended* to that parent.

### If a function uses setLastError(), then say in the function header that getLastError() is useful.

  • return: TRUE on success, FALSE on failure (check getLastError())
(bool) importFromString ($xmlString $xmlString, [$absoluteParentPath $absoluteParentPath = ''])
  • $xmlString $xmlString: (string) Name of the string to be read and parsed.
  • $absoluteParentPath $absoluteParentPath: (string) Node to append data too (see above)
match (line 2368)

Matches (evaluates) an XPath query

This method tries to evaluate an XPath query by parsing it. A XML source must have been imported before this method is able to work.

  • return: The result of the XPath expression. Either: node-set (an ordered collection of absolute references to nodes without duplicates) boolean (true or false) number (a floating-point number) string (a sequence of UCS characters)
(mixed) match ($xPathQuery $xPathQuery, [$baseXPath $baseXPath = ''])
  • $xPathQuery $xPathQuery: (string) XPath query to be evaluated.
  • $baseXPath $baseXPath: (string) (default is super-root) XPath query to a single document node, from which the XPath query should start evaluating.
reindexNodeTree (line 2159)

Update nodeIndex and every node of the node-tree.

Call after you have finished any tree modifications other wise a match with an xPathQuery will produce wrong results. The $this->nodeIndex[] is recreated and every nodes optimization data is updated. The optimization data is all the data that is duplicate information, would just take longer to find. Child nodes with value NULL are removed from the tree.

By default the modification functions in this component will automatically re-index the nodes in the tree. Sometimes this is not the behaver you want. To surpress the reindex, set the functions $autoReindex to FALSE and call reindexNodeTree() at the end of your changes. This sometimes leads to better code (and less CPU overhead).

Sample: ======= Given the xml is <AAA><B/>.<B/>.<B/></AAA> | Goal is <AAA>.<B/>.</AAA> (Delete B[1] and B[3]) $xPathSet = $xPath->match('//B'); # Will result in array('/AAA[1]/B[1]', '/AAA[1]/B[2]', '/AAA[1]/B[3]'); Three ways to do it. 1) Top-Down (with auto reindexing) - Safe, Slow and you get easily mix up with the the changing node index removeChild('/AAA[1]/B[1]'); // B[1] removed, thus all B[n] become B[n-1] !! removeChild('/AAA[1]/B[2]'); // Now remove B[2] (That originaly was B[3]) 2) Bottom-Up (with auto reindexing) - Safe, Slow and the changing node index (caused by auto-reindex) can be ignored. for ($i=sizeOf($xPathSet)-1; $i>=0; $i--) { if ($i==1) continue; removeChild($xPathSet[$i]); } 3) // Top-down (with *NO* auto reindexing) - Fast, Safe as long as you call reindexNodeTree() foreach($xPathSet as $xPath) { // Specify no reindexing if ($xPath == $xPathSet[1]) continue; removeChild($xPath, $autoReindex=FALSE); // The object is now in a slightly inconsistent state. } // Finally do the reindex and the object is consistent again reindexNodeTree();

(bool) reindexNodeTree ()
reset (line 970)

Resets the object so it's able to take a new xml sting/file

Constructing objects is slow. If you can, reuse ones that you have used already by using this reset() function.

void reset ()

Redefinition of:
XPathBase::reset()
Resets the object so it's able to take a new xml sting/file

Redefined in descendants as:
  • XPath::reset() : Resets the object so it's able to take a new xml sting/file
setCaseFolding (line 1048)

Alternative way to control whether case-folding is enabled for this XML parser.

Short cut to setXmlOptions(XML_OPTION_CASE_FOLDING, TRUE/FALSE)

When it comes to XML, case-folding simply means uppercasing all tag- and attribute-names (NOT the content) if set to TRUE. Note if you have this option set, then your XPath queries will also be case folded for you.

  • see: XML parser functions in PHP doc
void setCaseFolding ([$onOff $onOff = TRUE])
  • $onOff $onOff: (bool) (default TRUE)
setSkipWhiteSpaces (line 1069)

Alternative way to control whether skip-white-spaces is enabled for this XML parser.

Short cut to setXmlOptions(XML_OPTION_SKIP_WHITE, TRUE/FALSE)

When it comes to XML, skip-white-spaces will trim the tag content. An XML file with no whitespace will be faster to process, but will make your data less human readable when you come to write it out.

Running with this option on will slow the class down, so if you want to speed up your XML, then run it through once skipping white-spaces, then write out the new version of your XML without whitespace, then use the new XML file with skip whitespaces turned off.

  • see: XML parser functions in PHP doc
void setSkipWhiteSpaces ([$onOff $onOff = TRUE])
  • $onOff $onOff: (bool) (default TRUE)
setXmlOption (line 1017)

Set an xml_parser_set_option()

  • see: XML parser functions in PHP doc
void setXmlOption ($optionID $optionID, $value $value)
  • $optionID $optionID: (int) The option ID (e.g. XML_OPTION_SKIP_WHITE)
  • $value $value: (int) The option value.
setXmlOptions (line 1028)

Sets a number of xml_parser_set_option()s

void setXmlOptions ([$userXmlOptions $userXmlOptions = array()])
  • $userXmlOptions $userXmlOptions: (array) An array of parser options.
wholeText (line 1115)

Get a the content of a node text part or node attribute.

If the absolute Xpath references an attribute (Xpath ends with @ or attribute::), then the text value of that node-attribute is returned. Otherwise the Xpath is referencing a text part of the node. This can be either a direct reference to a text part (Xpath ends with text()[<nr>]) or indirect reference (a simple abs. Xpath to a node). 1) Direct Reference (xpath ends with text()[<part-number>]): If the 'part-number' is omitted, the first text-part is assumed; starting by 1. Negative numbers are allowed, where -1 is the last text-part a.s.o. 2) Indirect Reference (a simple abs. Xpath to a node): Default is to return the *whole text*; that is the concated text-parts of the matching node. (NOTE that only in this case you'll only get a copy and changes to the returned value wounld have no effect). Optionally you may pass a parameter $textPartNr to define the text-part you want; starting by 1. Negative numbers are allowed, where -1 is the last text-part a.s.o.

NOTE I : The returned value can be fetched by reference E.g. $text =& wholeText(). If you wish to modify the text. NOTE II: text-part numbers out of range will return FALSE SIDENOTE:The function name is a suggestion from W3C in the XPath specification level 3.

  • return: A *reference* to the text if the node that the other parameters describe or FALSE if the node is not found.
(&string) &wholeText ($absoluteXPath $absoluteXPath, [$textPartNr $textPartNr = NULL])
  • $absoluteXPath $absoluteXPath: (string) xpath to the node (See above).
  • $textPartNr $textPartNr: (int) If referring to a node, specifies which text part to query.
_addLiteral (line 2521)

Adds a literal to our array of literals

In order to make sure we don't interpret literal strings as XPath expressions, we have to encode literal strings so that we know that they are not XPaths.

  • return: A reference string to this literal.
(mixed) _addLiteral ($string $string)
  • $string $string: (string) The literal string that we need to store for future access
_asLiteral (line 2492)

Returns the given string as a literal reference.

  • return: The literal string. FALSE if the string isn't a literal reference.
(mixed) _asLiteral ($string $string)
  • $string $string: (string) The string that we are processing
_checkNodeTest (line 3713)

Checks whether a node matches a node-test.

This method checks whether a node in the document matches a given node-test. A node test is something like text(), node(), or an element name.

  • return: This method returns TRUE if the node matches the node-test, otherwise FALSE.
  • see: XPathEngine::evaluate()
(boolean) _checkNodeTest ($contextPath $contextPath, $nodeTest $nodeTest)
  • $contextPath $contextPath: (string) Full xpath of the node, which should be tested for matching the node-test.
  • $nodeTest $nodeTest: (string) String containing the node-test for the node.
_checkPredicates (line 3561)

Checks whether a node matches predicates.

This method checks whether a list of nodes passed to this method match a given list of predicates.

(array) _checkPredicates ($xPathSet $xPathSet, $predicates $predicates)
  • $xPathSet $xPathSet: (array) Array of full paths of all nodes to be tested.
  • $predicates $predicates: (array) Array of predicates to use.
_createSuperRoot (line 2036)

Creates a super root node.

void _createSuperRoot ()
_evaluateExpr (line 2858)

Evaluates an XPath Expr

$this->evaluate() is the entry point and does some inits, while this function is called recursive internaly for every sub-xPath expresion we find. It handles the following syntax, and calls evaluatePathExpr if it finds that none of this grammer applies.

http://www.w3.org/TR/xpath#section-Basics

[14] Expr ::= OrExpr [21] OrExpr ::= AndExpr | OrExpr 'or' AndExpr [22] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr [23] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr | EqualityExpr '!=' RelationalExpr [24] RelationalExpr ::= AdditiveExpr | RelationalExpr '<' AdditiveExpr | RelationalExpr '>' AdditiveExpr | RelationalExpr '<=' AdditiveExpr | RelationalExpr '>=' AdditiveExpr [25] AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr [26] MultiplicativeExpr ::= UnaryExpr | MultiplicativeExpr MultiplyOperator UnaryExpr | MultiplicativeExpr 'div' UnaryExpr | MultiplicativeExpr 'mod' UnaryExpr [27] UnaryExpr ::= UnionExpr | '-' UnaryExpr [18] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr

NOTE: The effect of the above grammar is that the order of precedence is (lowest precedence first): 1) or 2) and 3) =, != 4) <=, <, >=, > 5) +, - 6) *, div, mod 7) - (negate) 8) |

  • return: The result of the XPath expression. Either: node-set (an ordered collection of nodes without duplicates) boolean (true or false) number (a floating-point number) string (a sequence of UCS characters)
  • see: XPathEngine::evaluate()
(mixed) _evaluateExpr ($xPathQuery $xPathQuery, $context $context)
  • $xPathQuery $xPathQuery: (string) XPath query to be evaluated.
  • $context $context: (array) An associative array the describes the context from which to evaluate the XPath Expr. Contains three members: 'nodePath' => The absolute XPath expression to the context node 'size' => The context size 'pos' => The context position
_evaluateFunction (line 3656)

Evaluates an XPath function

This method evaluates a given XPath function with its arguments on a specific node of the document.

  • return: This method returns the result of the evaluation of the function. Depending on the function the type of the return value can be different.
  • see: XPathEngine::evaluate()
(mixed) _evaluateFunction ($function $function, $arguments $arguments, $context $context)
  • $function $function: (string) Name of the function to be evaluated.
  • $arguments $arguments: (string) String containing the arguments being passed to the function.
  • $context $context: (array) The context from which to evaluate
_evaluateOperator (line 3109)

Evaluate the result of an operator whose operands have been evaluated

If the operator type is not "NodeSet", then neither the left or right operators will be node sets, as the processing when one or other is an array is complex, and should be handled by the caller.

  • return: The result of the XPath expression. Either: node-set (an ordered collection of nodes without duplicates) boolean (true or false) number (a floating-point number) string (a sequence of UCS characters)
(mixed) _evaluateOperator ($left $left, $right $operator, $operator $right, $operatorType $operatorType, $context $context)
  • $left $left: (mixed) The left operand
  • $right $operator: (mixed) The right operand
  • $operator $right: (string) The operator to use to combine the operands
  • $operatorType $operatorType: (string) The type of the operator. Either 'Boolean', 'Integer', 'String', or 'NodeSet'
  • $context $context: (array) The context from which to evaluate
_evaluatePathExpr (line 3295)

Evaluates an XPath PathExpr

It handles the following syntax:

http://www.w3.org/TR/xpath#node-sets http://www.w3.org/TR/xpath#NT-LocationPath http://www.w3.org/TR/xpath#path-abbrev http://www.w3.org/TR/xpath#NT-Step

[19] PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath [20] FilterExpr ::= PrimaryExpr | FilterExpr Predicate [1] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath [2] AbsoluteLocationPath ::= '/' RelativeLocationPath? | AbbreviatedAbsoluteLocationPath [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath [4] Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier [10] AbbreviatedAbsoluteLocationPath ::= '//' RelativeLocationPath [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step [12] AbbreviatedStep ::= '.' | '..' [13] AbbreviatedAxisSpecifier ::= '@'?

If you expand all the abbreviated versions, then the grammer simplifies to:

[19] PathExpr ::= RelativeLocationPath | '/' RelativeLocationPath? | FilterExpr | FilterExpr '/' RelativeLocationPath [20] FilterExpr ::= PrimaryExpr | FilterExpr Predicate [3] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step [4] Step ::= AxisName '::' NodeTest Predicate*

Conceptually you can say that we should split by '/' and try to treat the parts as steps, and if that fails then try to treat it as a PrimaryExpr.

  • return: The result of the XPath expression. Either: node-set (an ordered collection of nodes without duplicates) boolean (true or false) number (a floating-point number) string (a sequence of UCS characters)
  • see: XPathEngine::evaluate()
(mixed) _evaluatePathExpr ($PathExpr $PathExpr, $context $context)
  • $PathExpr $PathExpr: (string) PathExpr syntactical element
  • $context $context: (array) The context from which to evaluate
_evaluatePrimaryExpr (line 2697)

Evaluates an XPath PrimaryExpr

http://www.w3.org/TR/xpath#section-Basics

[15] PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall

  • return: An empty string if the query was successfully parsed and evaluated, else a string containing the reason for failing.
  • see: XPathEngine::evaluate()
(string) _evaluatePrimaryExpr ($xPathQuery $xPathQuery, $context $context, $results &$result)
  • $xPathQuery $xPathQuery: (string) XPath query to be evaluated.
  • $context $context: (array) The context from which to evaluate
  • $results &$result: (mixed) If the expression could be parsed and evaluated as one of these syntactical elements, then this will be either:
    • node-set (an ordered collection of nodes without duplicates)
    • boolean (true or false)
    • number (a floating-point number)
    • string (a sequence of UCS characters)
_evaluateStep (line 3463)

Evaluate a step from a XPathQuery expression at a specific contextPath.

Steps are the arguments of a XPathQuery when divided by a '/'. A contextPath is a absolute XPath (or vector of XPaths) to a starting node(s) from which the step should be evaluated.

(array) _evaluateStep ($steps $steps, $context $context)
  • $steps $steps: (array) Vector containing the remaining steps of the current XPathQuery expression.
  • $context $context: (array) The context from which to evaluate
_export (line 1336)

Generates a XML string with the content of the current document.

This is the start for extracting the XML-data from the node-tree. We do some preperations and then call _InternalExport() to fetch the main XML-data. You optionally may pass xpath to any node that will then be used as top node, to extract XML-parts of the document. Default is '', meaning to extract the whole document.

You also may pass a 'xmlHeader' (usually something like <?xml version="1.0"? > that will overwrite any other 'xmlHeader', if there was one in the original source. If there wasn't one in the original source, and you still don't specify one, then it will use a default of <?xml version="1.0"? > Finaly, when exporting to HTML, you may pass a vector xPaths you want to hi-light. The hi-lighted tags and attributes will receive a nice color.

NOTE I : The output can have 2 formats: a) If "skip white spaces" is/was set. (Not Recommended - slower) The output is formatted by adding indenting and carriage returns. b) If "skip white spaces" is/was *NOT* set. 'as is'. No formatting is done. The output should the same as the the original parsed XML source.

  • return: The xml string, or FALSE on error.
(mixed) _export ([$absoluteXPath $absoluteXPath = ''], [$xmlHeader $xmlHeader = NULL], [$hilightXpath $hilightXpathList = ''])
  • $absoluteXPath $absoluteXPath: (string) (optional, default is root) The node we choose as top-node
  • $xmlHeader $xmlHeader: (string) (optional) content before <root/> (see text above)
  • $hilightXpath $hilightXpathList: (array) (optional) a vector of xPaths to nodes we wat to hi-light (see text above)
_generate_ids (line 2173)

Create the ids that are accessable through the generate-id() function