dom_import_simplexml> <DOMXPath->query()
Last updated: Mon, 28 Dec 2009

DOMXPath->registerNamespace()

(No version information available, might be only in CVS)

DOMXPath->registerNamespace() — Registers the namespace with the DOMXPath object

Descrição

DOMXPath
bool registerNamespace ( string $prefix , string $namespaceURI )

Registers the namespaceURI and prefix with the DOMXPath object.

Parâmetros

prefix

The prefix.

namespaceURI

The URI of the namespace.

Valor Retornado

Retorna TRUE em caso de sucesso ou FALSE em falhas.



User Contributed Notes
DOMXPath->registerNamespace()
cameron kellough
15-Apr-2007 02:33
This is called prefix mapping and it is necessary to use xpath to handle documents which have default namespaces. //root/item will search for items with no namespace, not items with the namespace described as the default in the xmlns declaration.  This problem is maddening as it just looks on the surface like xpath isn't working.
spam at spam dot spam
31-Mar-2005 05:46
It is mentioned in a few places on the web, but it wasn't mentioned here. You need to use this function to set up a prefix for the default namespace of a document.

For instance, if you are trying to parse a Microsoft Spreadsheet XML file, which has the default namespace of "urn:schemas-microsoft-com:office:spreadsheet":

$doc = DOMDocument::load("my_spreadsheet.xml);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace("m",
        "urn:schemas-microsoft-com:office:spreadsheet");
$query = '/m:Workbook/m:Worksheet[1]/m:Table';
$result = $xpath->query($query, $doc);

You can use anything in place of the 'm', but you have to specify something! Just asking for "/Workbook/Worksheet/Table" doesn't work.

dom_import_simplexml> <DOMXPath->query()
Last updated: Mon, 28 Dec 2009