Class: XPath
Source Location: /lib/XPath/XPath.class.php
XPathBase
|
--XPathEngine
|
--XPath
**********************************************************************************************
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
Class Methods
constructor XPath [line 4531]
XPath XPath(
[$userXmlOptions
$fileName = ''], [$fileName
$userXmlOptions = array()])
|
|
Constructor of the class Optionally you may call this constructor with the XML-filename to parse and the XML option vector. A option vector sample: $xmlOpt = array(XML_OPTION_CASE_FOLDING => FALSE, XML_OPTION_SKIP_WHITE => TRUE);
Tags:
Parameters:
method appendChild [line 4943]
(mixed) appendChild(
$xPathQuery
$xPathQuery, $node
$node, [$afterText
$afterText = FALSE], [$autoReindex
$autoReindex = TRUE])
|
|
Appends a child to anothers children. If you intend to do a lot of appending, you should leave autoIndex as FALSE and then call reindexNodeTree() when you are finished all the appending.
Tags:
Parameters:
method appendData [line 5309]
(bool) appendData(
$xPathQuery
$xPathQuery, $data
$data, [$textPartNr
$textPartNr = 1])
|
|
Append text data to the end of the text for an attribute OR node text-part. This method adds content to a node. If it's an attribute node, then the value of the attribute will be set, otherwise the passed data will append to character data of the node text-part. Per default the first text-part is taken. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method deleteData [line 5335]
(bool) deleteData(
$xPathQuery
$xPathQuery, [$offset
$offset = 0], [$count
$count = 0], [$textPartNr
$textPartNr = 1])
|
|
Delete the data of a node. This method deletes content of a node. If it's an attribute node, then the value of the attribute will be removed, otherwise the node text-part. will be deleted. Per default the first text-part is deleted. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method getAttributes [line 5049]
(mixed) getAttributes(
$absoluteXPath
$absoluteXPath, [$attrName
$attrName = NULL])
|
|
Retrieves a dedecated attribute value or a hash-array of all attributes of a node. The first param $absoluteXPath must be a valid xpath OR a xpath-query that results to *one* xpath. If the second param $attrName is not set, a hash-array of all attributes of that node is returned. Optionally you may pass an attrubute name in $attrName and the function will return the string value of that attribute.
Tags:
Parameters:
method getData [line 5179]
(mixed) getData(
$xPathQuery
$xPathQuery)
|
|
Retrieve all the text from a node as a single string. Sample Given is: <AA> This <BB\>is <BB\> some<BB\>text </AA> Return of getData('/AA[1]') would be: " This is sometext " The first param $xPathQuery must be a valid xpath OR a xpath-query that results to *one* xpath.
Tags:
Parameters:
method getDataParts [line 5201]
(mixed) getDataParts(
$xPathQuery
$xPathQuery)
|
|
Retrieve all the text from a node as a vector of strings Where each element of the array was interrupted by a non-text child element. Sample Given is: <AA> This <BB\>is <BB\> some<BB\>text </AA> Return of getDataParts('/AA[1]') would be: array([0]=>' This ', [1]=>'is ', [2]=>' some', [3]=>'text '); The first param $absoluteXPath must be a valid xpath OR a xpath-query that results to *one* xpath.
Tags:
Parameters:
method insertBefore [line 5023]
(mixed) insertBefore(
$xPathQuery
$xPathQuery, $node
$node, [$afterText
$afterText = TRUE], [$autoReindex
$autoReindex = TRUE])
|
|
Inserts a node before the reference node with the same parent. If you intend to do a lot of appending, you should leave autoIndex as FALSE and then call reindexNodeTree() when you are finished all the appending.
Tags:
Parameters:
method insertChild [line 4845]
(mixed) insertChild(
$xPathQuery
$xPathQuery, $node
$node, [$shiftRight
$shiftRight = TRUE], [$afterText
$afterText = TRUE], [$autoReindex
$autoReindex = TRUE])
|
|
Insert passed node (or passed node-tree) at the node(s) that matches the xQuery. With parameters you can define if the 'hit'-node is shifted to the right or left and if it's placed before of after the text-part. Per derfault the 'hit'-node is shifted to the right and the node takes the place the of the 'hit'-node. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected. E.g. Following is given: AAA[1] / \ ..BBB[1]..BBB[2] .. a) insertChild('/AAA[1]/BBB[2]', <node CCC>) b) insertChild('/AAA[1]/BBB[2]', <node CCC>, $shiftRight=FALSE) c) insertChild('/AAA[1]/BBB[2]', <node CCC>, $shiftRight=FALSE, $afterText=FALSE) a) b) c) AAA[1] AAA[1] AAA[1] / | \ / | \ / | \ ..BBB[1]..CCC[1]BBB[2].. ..BBB[1]..BBB[2]..CCC[1] ..BBB[1]..BBB[2]CCC[1].. #### Do a complete review of the "(optional)" tag after several arguments.
Tags:
Parameters:
method insertData [line 5289]
(bool) insertData(
$xPathQuery
$xPathQuery, $data
$data, [$offset
$offset = 0])
|
|
Insert a sub string in a text-part OR attribute-value. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method nodeName [line 4599]
(mixed) nodeName(
$xPathQuery
$xPathQuery)
|
|
Retrieves the name(s) of a node or a group of document nodes. This method retrieves the names of a group of document nodes specified in the argument. So if the argument was '/A[1]/B[2]' then it would return 'B' if the node did exist in the tree.
Tags:
Parameters:
method removeAttribute [line 5140]
(bool) removeAttribute(
$xPathQuery
$xPathQuery, [$attrList
$attrList = NULL])
|
|
Removes an attribute of a node(s). This method removes *ALL* attributres per default unless the second parameter $attrList is set. $attrList can be either a single attr-name as string OR a vector of attr-names as array. E.g. removeAttribute(<xPath>); # will remove *ALL* attributes. removeAttribute(<xPath>, 'A'); # will only remove attributes called 'A'. removeAttribute(<xPath>, array('A_1','A_2')); # will remove attribute 'A_1' and 'A_2'. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method removeChild [line 4640]
(bool) removeChild(
$xPathQuery
$xPathQuery, [$autoReindex
$autoReindex = TRUE])
|
|
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. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method replaceChild [line 4760]
(array) &replaceChild(
$xPathQuery
$xPathQuery, $node
$node, [$autoReindex
$autoReindex = TRUE])
|
|
Replace the node(s) that matches the xQuery with the passed node (or passed node-tree) If the passed node is a string it's assumed to be XML and replaceChildByXml() will be called. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method replaceChildByData [line 4705]
(bool) replaceChildByData(
$xPathQuery
$xPathQuery, $data
$data, [$autoReindex
$autoReindex = TRUE])
|
|
Replace a node with any data string. The $data is taken 1:1. This function will delete the node you define by $absoluteXPath (plus it's sub-nodes) and substitute it by the string $text. Often used to push in not well formed HTML. WARNING: The $data is taken 1:1. You are in charge that the data you enter is valid XML if you intend to export and import the content again. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method replaceData [line 5264]
(bool) replaceData(
$xPathQuery
$xPathQuery, $replacement
$replacement, [$offset
$offset = 0], [$count
$count = 0], [$textPartNr
$textPartNr = 1])
|
|
Replace a sub string of a text-part OR attribute-value. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method reset [line 4547]
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.
Overrides XPathEngine::reset() (Resets the object so it's able to take a new xml sting/file)
method setAttribute [line 5082]
(bool) setAttribute(
$xPathQuery
$xPathQuery, $name
$name, $value
$value, [$overwrite
$overwrite = TRUE])
|
|
Set attributes of a node(s). This method sets a number single attributes. An existing attribute is overwritten (default) with the new value, but setting the last param to FALSE will prevent overwritten. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method setAttributes [line 5100]
(bool) setAttributes(
$xPathQuery
$xPathQuery, $attributes
$attributes, [$overwrite
$overwrite = TRUE])
|
|
Version of setAttribute() that sets multiple attributes to node(s). This method sets a number of attributes. Existing attributes are overwritten (default) with the new values, but setting the last param to FALSE will prevent overwritten. NOTE: When passing a xpath-query instead of an abs. Xpath. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method setModMatch [line 4570]
void setModMatch(
[$modMatch
$modMatch = XPATH_QUERYHIT_ALL])
|
|
Resolves and xPathQuery array depending on the property['modMatch'] Most of the modification functions of XPath will also accept a xPathQuery (instead of an absolute Xpath). The only problem is that the query could match more the one node. The question is, if the none, the fist or all nodes are to be modified. The behaver can be set with setModMatch()
Tags:
Parameters:
method substringData [line 5241]
(mixed) substringData(
$absoluteXPath
$absoluteXPath, [$offset
$offset = 0], [$count
$count = NULL])
|
|
Retrieves a sub string of a text-part OR attribute-value. This method retrieves the sub string of a specific text-part OR (if the $absoluteXPath references an attribute) the the sub string of the attribute value. If no 'direct referencing' is used (Xpath ends with text()[<part-number>]), then the first text-part of the node ist returned (if exsiting).
Tags:
Parameters:
method _getTextSet [line 5400]
(mixed) _getTextSet(
$xPathQuery
$xPathQuery, [$textPartNr
$textPartNr = 1])
|
|
Get a reference-list to node text part(s) or node attribute(s). If the Xquery references an attribute(s) (Xquery ends with attribute::), then the text value of the node-attribute(s) is/are returned. Otherwise the Xquery is referencing to text part(s) of node(s). This can be either a direct reference to text part(s) (Xquery ends with text()[<nr>]) or indirect reference (a simple Xquery to node(s)). 1) Direct Reference (Xquery 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 Xquery to node(s)): Default is to return the first text part(s). 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 vector is a set of references to the text parts / attributes. This is handy, if you wish to modify the contents. NOTE II: text-part numbers out of range will not be in the list NOTE III:Instead of an absolute xpath you may also pass a xpath-query. Depending on setModMatch() one, none or multiple nodes are affected.
Tags:
Parameters:
method _resolveXPathQuery [line 5549]
(array) _resolveXPathQuery(
$xPathQuery
$xPathQuery, $function
$function)
|
|
Resolves an xPathQuery vector depending on the property['modMatch'] To: - all matches,
- the first
- none (If the query matches more then one node.)
see setModMatch() for details
Tags:
Parameters:
method _resolveXPathQueryForNodeMod [line 5512]
(array) _resolveXPathQueryForNodeMod(
$xPathQuery
$xPathQuery, $function
$functionName)
|
|
Resolves an xPathQuery vector for a node op for modification It is possible to create a brand new object, and try to append and insert nodes into it, so this is a version of _resolveXPathQuery() that will autocreate the super root if it detects that it is not present and the $xPathQuery is empty. Also it demands that there be at least one node returned, and displays a suitable error message if the returned xPathSet does not contain any nodes.
Tags:
Parameters:
method _xml2Document [line 5357]
(&array) &_xml2Document(
$xmlString
$xmlString)
|
|
Parse the XML to a node-tree. A so called 'document'
Tags:
Parameters:
|
|