I am trying to query an XML document that uses namespaces. I had success with xpath without namespaces, but there were no results with namespaces. This is a basic example of what I tried. I squeezed it a bit, so there may be small problems in my sample that can distract me from my real problem.
XML example:
<?xml version="1.0"?> <sf:page> <sf:section> <sf:layout> <sf:p>My Content</sf:p> </sf:layout> </sf:section> </sf:page>
PHP code example:
<?php $path = "index.xml"; $content = file_get_contents($path); $dom = new DOMDocument($content); $xpath = new DOMXPath($dom); $xpath->registerNamespace('sf', "http://developer.apple.com/namespaces/sf"); $p = $xpath->query("//sf:p", $dom);
My result: "p" is a "DOMNodeList Object ()", and the length is 0. Any help would be appreciated.
source share