XML_XPath
[ class tree: XML_XPath ] [ index: XML_XPath ] [ all elements ]

Class: XML_XPath_common

Source Location: /XML_XPath-1.2.4/XPath/common.php

Class Overview


The XML_XPath_common class contains the DOM functions used to manipulate


Author(s):

Version:

  • Revision: 1.1

Variables

Methods


Child classes:

XML_XPath_result
Interface for an XML_XPath result so that one can cycle through the result set and manipulate the main tree with DOM methods using a seperate pointer then the original class.
XML_XPath
The main "XML_XPath" class is simply a container class with some methods for creating DOM xml objects and preparing error codes

Inherited Variables

Inherited Methods


Class Details

[line 99]
The XML_XPath_common class contains the DOM functions used to manipulate

and maneuver through the xml tree. The main thing to understand is that all operations work around a single pointer. This pointer is your place holder within the document. Each function you run assumes the node in reference is your pointer. However, every function can take an xpath query or DOM object reference, so that the pointer can be set before working on the node, and can retain this position if specified. Every DOM function call has a init() and shutdown() call. This function prepares the pointer to the requested location in the tree if an xpath query or pointer object is provided. In addition, the init() function checks to see that the node type is acceptable for the method, and if not throws an XML_XPath_Error exception. If you want to execute a function and then remain in the location of your query, then you specify that you want to move the pointer. For the DOM step functions, this is the default action.

Note: All offsets in the CharacterData interface start from 0.

The object model of XML_XPath is as follows (indentation means inheritance):

XML_XPath_common The main functionality of the XML_XPath class is here. This | holds all the DOM functions for manipulating and maneuvering | through the DOM tree. | +-XML_XPath The frontend for the XML_XPath implementation. Provides default | functions for preparing the main document, running xpath queries | and handling errorMessages. | +-Result Extended from the XML_XPath_common class, this object is returned when an xpath query is executed and can be used to cycle through the result nodeset or data

  • Author: Dan Allen <dan@mojavelinux.com>
  • Version: Revision: 1.1
  • Since: PHP 4.2.1
  • Access: public


[ Top ]


Class Variables

$bookmark =

[line 112]

domxml node bookmark used for holding a place in the xml document

Type:   object


[ Top ]

$pointer =

[line 106]

domxml node of the current location in the xml document

Type:   object


[ Top ]

$skipBlanks =  true

[line 118]

when working with the xml document, ignore the presence of blank nodes (white space)

Type:   boolean


[ Top ]

$xmllint =  'xmllint'

[line 125]

path to xmllint used for reformating the xml output

[!] should be using System_Command for this [!]


Type:   string


[ Top ]



Method Detail

appendChild   [line 939]

object pointer appendChild( mixed $in_xmlData, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Adds the node or document fragment to the end of the list of children. If the node is already in the tree it is first removed (not sure if this works yet)
  • Return: to the first of the nodes appended {or XML_XPath_Error exception}
  • Access: public

Parameters:

mixed   $in_xmlData   —  string document fragment or node
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  move internal pointer

[ Top ]

appendData   [line 868]

void appendData( string $in_content, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Will append data to end of text node.
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_content   —  content to append
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

childNodes   [line 205]

object XML_XPath_result &childNodes( )

Retrieves the child nodes from the element node as an XML_XPath_result object

Similar to an xpath query, this function will grab all the first descendant child nodes of the element node at the current position and will create an XML_XPath_result object of type nodeset with each of the child nodes as the nodes. DOM query functions do not take an xpathQuery argument

  • Return: object of type nodeset [!] important note: since we had to hack the result object a bit, you cannot sort the result object when generated in this manner right now [!]
  • Access: public

[ Top ]

cloneNode   [line 1072]

object cloned cloneNode( [bool $in_deep = false], [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Clones the node and return the node as a result object
  • Return: node of the current node, ready to be put in another document
  • Access: public

Parameters:

bool   $in_deep   —  (optional) clone node children
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

deleteData   [line 830]

void deleteData( [int $in_offset = 0], [int $in_count = 0], [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Will delete data at offset and for count for a text node.
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

int   $in_offset   —  (optional) offset to delete data
int   $in_count   —  (optional) number of characters to delete
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

documentElement   [line 253]

boolean documentElement( [boolean $in_movePointer = true])

Move to the document element
  • Return: whether pointer was moved or object pointer to document element
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

dumpChildren   [line 1155]

string dumpChildren( [string $in_xpathQuery = null], [boolean $in_movePointer = false], [ $in_format = true])

Returns all the contents of an element node, regardless of type, as is.
  • Return: xml string, a concatenation of all the children of the element node
  • Access: public

Parameters:

string   $in_xpathQuery   —  quick xpath query
boolean   $in_movePointer   —  move internal pointer
   $in_format   — 

[ Top ]

evaluate   [line 1427]

mixed &evaluate( string $in_xpathQuery, [boolean $in_movePointer = false])

Evaluate the xpath expression on the loaded xml document.

The xpath query provided is evaluated and either an XML_XPath_result object is returned, or, if the pointer is being moved, it acts like a glorified step function and moves the pointer to the specified node (or first node if it is a set) and returns a boolean success

  • Return: result object or boolean success (for move pointer)
  • Throws: XML_XPath_error XML_XPATH_NOT_LOADED
  • Access: public

Parameters:

string   $in_xpathQuery   —  xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

firstChild   [line 423]

boolean firstChild( [boolean $in_movePointer = true])

Moves the pointer to the first child of this node or returns the first node.

If the flag is on to skip blank nodes then the first non-blank node is used. Step functions do not take an xpathQuery argument

  • Return: whether the pointer was moved to the first child or returns the first child
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

getAttribute   [line 662]

string getAttribute( string $in_name, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Retrieves an attribute value by name from the element node at the current pointer.

Grab the attribute value if it exists and return it. If the attribute does not exist, this function will return the boolean 'false', so be sure to check properly if the value is "" or if the attribute doesn't exist at all. This function is the only attribute function which allows you to step onto the attribute node.

  • Return: value of attribute or false if attribute DNE {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_name   —  Name of the attribute
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move the internal pointer with quick xpath query

[ Top ]

getAttributes   [line 620]

array getAttributes( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Return an associative array of attribute names as the keys and attribute values as the values. This is not a DOM function, but is a convenient addition.
  • Return: associative array of attributes {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

getElementsByTagName   [line 235]

object XML_XPath_result getElementsByTagName( string $in_tagName)

Create an XML_XPath_result object with the elements with the specified tagname

DOM query functions do not take an xpathQuery argument

  • Return: object of matching nodes
  • Access: public

Parameters:

string   $in_tagName   — 

[ Top ]

getNodePath   [line 1304]

string getNodePath( $in_node, string $in_xpathQuery, boolean $in_movePointer)

Resolve the xpath location of the current node
  • Return: xpath location query
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional)
boolean   $in_movePointer   —  (optional)
   $in_node   — 

[ Top ]

getOne   [line 1399]

mixed getOne( string $in_xpathQuery, [boolean $in_movePointer = false])

A quick version of the evaluate, where the results are returned immediately. This function is equivalent to xsl:value-of select in every way.
  • Return: number of nodes or value of scalar result {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

getPointer   [line 1260]

object current getPointer( )

Get the current pointer in the xml document.
  • Return: pointer object
  • Access: public

[ Top ]

hasAttribute   [line 588]

boolean hasAttribute( string $in_name, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Returns true when an attribute with a given name is specified on this element false otherwise.
  • Return: existence of attribute {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_name   —  name of attribute
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

hasAttributes   [line 555]

boolean hasAttributes( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Returns whether this node has any attributes.
  • Return: attributes exist {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

hasChildNodes   [line 524]

boolean hasChildNodes( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Returns whether this node has any children.
  • Return: has child nodes {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

insertBefore   [line 989]

object pointer insertBefore( mixed $in_xmlData, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Inserts the node before the current pointer.
  • Return: to the first of the new inserted nodes
  • Access: public

Parameters:

mixed   $in_xmlData   —  either a document fragment xml string or a node
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

insertData   [line 811]

void insertData( string $in_content, [int $in_offset = 0], [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Will insert data at offset for a text node.
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_content   —  content to be inserted
int   $in_offset   —  offset to insert data
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

lastChild   [line 474]

boolean lastChild( [boolean $in_movePointer = true])

Moves the pointer to the last child of this node or returns the last child.

If the flag is on to skip blank nodes then the first non-blank node is used. Step functions do not take an xpathQuery argument

  • Return: whether the pointer was moved to the last child or returns the last child
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

nextSibling   [line 315]

boolean nextSibling( [boolean $in_movePointer = true])

Moves the internal pointer to the next sibling of the current node, or returns the pointer.

If the flag is on to skip blank nodes then the first non-blank node is used. Step functions do not take an xpathQuery argument

  • Return: whether the pointer was moved or object pointer to next sibling
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

nodeName   [line 139]

string nodeName( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Return the name of this node, depending on its type, according to the DOM recommendation
  • Return: name of node corresponding to DOM recommendation {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer with quick xpath query

[ Top ]

nodeType   [line 170]

int nodeType( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Returns the integer value constant corresponding to the DOM node type
  • Return: DOM type of the node {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer with quick xpath query

[ Top ]

parentNode   [line 281]

boolean parentNode( [boolean $in_movePointer = true])

Moves the internal pointer to the parent of the current node or returns the pointer.

Step functions do not take an xpathQuery argument

  • Return: whether pointer was moved or object pointer to parent
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

previousSibling   [line 372]

boolean previousSibling( [boolean $in_movePointer = true])

Moves the internal pointer to the previous sibling of the current node or returns the pointer.

If the flag is on to skip blank nodes then the first non-blank node is used. Step functions do not take an xpathQuery argument

  • Return: whether the pointer was moved or object pointer to previous sibling
  • Access: public

Parameters:

boolean   $in_movePointer   —  (optional) move the internal pointer or return reference

[ Top ]

removeAttribute   [line 733]

boolean removeAttribute( string $in_name, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Remove the attribute by name.
  • Return: success {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_name   —  name of the attribute
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

removeChild   [line 1035]

object cloned removeChild( [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Removes the child node at the current pointer and returns it.

This function will remove a child from the list of children and will move the pointer to the parent node.

  • Return: node of the removed node, ready to be put in another document
  • Access: public

Parameters:

string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

replaceChild   [line 888]

object pointer replaceChild( mixed $in_xmlData, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Replaces the old child with the new child. If the new child is already in the document, it is first removed (not implemented yet). If the new child is a document fragment, then all of the nodes are inserted in the location of the old child.
  • Return: to old node {or XML_XPath_Error exception}
  • Access: public

Parameters:

mixed   $in_xmlData   —  document fragment or node
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

replaceChildren   [line 1106]

void replaceChildren( $in_xmlData, [string $in_xpathQuery = null], [boolean $in_movePointer = false], string $in_fragment)

Not in the DOM specification, but certainly a convenient function. Allows you to pass in an xml document fragment which will be parsed into an xml object and merged into the xml document, replacing all the previous children of the node. It does this by shallow cloning the node, restoring the attributes and then adding the parsed children.
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_fragment   —  xml fragment which will be merged into tree
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer
   $in_xmlData   — 

[ Top ]

replaceData   [line 850]

void replaceData( string $in_content, [int $in_offset = 0], [int $in_count = 0], [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Will replace data at offset and for count with content
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_content   —  content to insert
int   $in_offset   —  (optional) offset to replace data
int   $in_count   —  (optional) number of characters to replace
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

setAttribute   [line 701]

boolean setAttribute( string $in_name, string $in_value, [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter.

Invalid characters are escaped.

  • Return: success {or XML_XPath_Error exception}
  • Access: public

Parameters:

string   $in_name   —  name of the attribute to be set
string   $in_value   —  new attribute value
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

setPointer   [line 1276]

void setPointer( object $in_node)

Set the pointer in the xml document
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

object   $in_node   —  node to move to in the xml document

[ Top ]

substringData   [line 769]

string substringData( [int $in_offset = 0], [int $in_count = 0], [string $in_xpathQuery = null], [boolean $in_movePointer = false])

Extracts a range of data from the node. Takes an offset and a count, which are optional and will default to retrieving the whole string. If an XML_ELEMENT_NODE provided, then it first concats all the adjacent text nodes recusively and works on those.

??? implement wholeText() which concats all text nodes adjacent to a text node ???

  • Return: substring of the character data {or XML_XPath_Error exception}
  • Access: public

Parameters:

int   $in_offset   —  offset of substring to extract
int   $in_count   —  length of substring to extract
string   $in_xpathQuery   —  (optional) quick xpath query
boolean   $in_movePointer   —  (optional) move internal pointer

[ Top ]

toFile   [line 1187]

void toFile( file $in_file, [int $in_compression = 0])

Exports the xml document to a file. Only works for the whole document right now.
  • Return: {or XML_XPath_Error exception}
  • Access: public

Parameters:

file   $in_file   —  file to export the xml to
int   $in_compression   —  (optional) ratio of compression using zlib (0-9)

[ Top ]

toString   [line 1222]

string toString( [string $in_xpathQuery = null], [boolean $in_movePointer = false], [boolean $in_format = true])

Export the xml document to a string, beginning from the pointer.
  • Return: xml string, starting at pointer
  • Access: public

Parameters:

string   $in_xpathQuery   —  quick xpath query
boolean   $in_movePointer   —  move internal pointer
boolean   $in_format   —  reformat using xmllint --format

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:44:42 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.