Integrating PHP and XML 2004

PHP.XPath is a Hypertext Preprocessor (PHP) class that searches and retrieves data from an eXtensible Markup Language (XML) document using XPath. The PHP.XPath class uses the Document Object Model (DOM) Application Programming Interface (API) to modify an XML document.

This appendix introduces the PHP.XPath class, and describes the types of objects in this class. It also explains the public and private methods of the objects in the PHP.XPath class.

Introducting the PHP.XPath Class

The PHP.XPath class accepts XML data as its argument, parses the data, and creates an object that represents XML data. This object uses the methods defined in the PHP.XPath class to create XML nodesets on the basis of XPath expressions. You can add, delete, or edit the nodes from an XML document tree, and retrieve specific information from within an XML document.

If the PHP module on your server is not compiled with the XML library, you can use the PHP.XPath class to provide XML functionality. The PHP.XPath class consists of objects of three base classes, which are:

Note  

You need not install the DOM XML PHP library to modify an XML document using the PHP.XPath class.

The XPathBase Class

The XPathBase class consists of public and private methods. A public method declared in a class is accessible to other classes. The public methods in the XPathBase class are:

setVerbose($level=1)

In the above syntax, the $level parameter is set to the default value, 1. To turn off the error-level reporting, set the value of the $level parameter to 0. If the $level parameter has an integer value greater than 1, error-level reporting is turned on.

Note  

The higher the value of the $level parameter, the higher is the level of error.

A private method is not accessible outside the class definition. The private methods in the XPathBase class are:

In the above syntax, the $expression parameter denotes the string to be searched; and the $term parameter indicates the string in which the _searchString() method searches the specified expression.

The _searchString() method returns an integer value. It returns the offset value at which the string is found. The _searchString() method returns “1, if the $expression parameter is not a substring of the string in the $term parameter.

In the above syntax, the $term parameter denotes the XPath string, in which the _bracketsCheck() method checks for a matching bracket.

In the above syntax, the $string parameter denotes the string from which the _prestr() method retrieves a substring. The $delimiter parameter denotes the string that contains the delimiter for the _prestr() method. If the $offset parameter is set to 0, the method searches the $string string, starting from the first character, until it finds the delimiter for the first instant.

If the $offset parameter is set to a value other than 0, the _prestr() method searches the $string string from the specified offset value. The _prestr() method returns a substring that precedes the specified delimiter in the original string. An example of the _prestr() method is:

_prestr(Park:Town,

Категории