Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP registerXPathNamespace() Function

PHP registerXPathNamespace() Function

PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual

Example

Create a namespace context for the next XPath query:

My Book Chapter 1 Donec velit. Nullam eget tellus... Chapter 2 Lorem ipsum dolor sit amet.... XML; $sxe=new SimpleXMLElement($xml); $sxe->registerXPathNamespace('c','http://example.org/chapter-title'); $result=$sxe->xpath('//c:title'); foreach ($result as $title) { echo $title . "
"; } ?>

Run Example »


Definition and Usage

The registerXPathNamespace() function creates a namespace context for the next XPath query.

This function is useful if the namespace prefix changes in the XML document. registerXPathNamespace() creates a specified namespace prefix so that the affected XML nodes can be accessed without changing the application code too much.


Syntax

registerXPathNamespace(

prefix

,

ns

);

Parameters Description
prefix Required. Specifies the ns namespace prefix used in the XPath query for the specified namespace.
ns Required. Specifies the namespace to use for the XPath query.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 5.2+

PHP SimpleXML Reference Manual PHP SimpleXML Reference Manual