note 105854 modified in domxpath.registernamespace by danbrown
| From: | danbrown@php.net | Date: | Tue, 20 Sep 2011 11:59:30 +0000 |
| Subject: | note 105854 modified in domxpath.registernamespace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183297@lists.php.net to get a copy of this message | ||
A general way to register the root default namespace:
<?php
$xml = new DomDocument();
$xml->load('data.xml');
$xpath = new DOMXPath($xml);
$rootNamespace = $xml->lookupNamespaceUri($xml->namespaceURI);
$xpath->registerNamespace('x', $rootNamespace);
?>
And then just query:
<?php $elementList = $xpath->query('//x:items/x:name'); ?>
--was--
A general way to register the root default namespace:
$xml = new DomDocument();
$xml->load('data.xml');
$xpath = new DOMXPath($xml);
$rootNamespace = $xml->lookupNamespaceUri($xml->namespaceURI);
$xpath->registerNamespace('x', $rootNamespace);
And then just query:
$elementList = $xpath->query('//x:items/x:name');
http://php.net/manual/en/domxpath.registernamespace.php