PHP Xpath with Multiple Namespaces
Posted: Mon Mar 01, 2010 2:34 pm
I'm trying to read a document with the following structure (some stripped out for brevity):
I'm trying to access the value via namespace, but it doesn't seem to be working with multiple namespaces. This is what I'm doing:
Is there some issue with using multiple namespaces in the document?
Code: Select all
<manifest
xmlns = "http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:lom="http://ltsc.ieee.org/xsd/LOM"
>
<organizations>
<organization>
<title>Title</title>
</organization>
</organizations>
<metadata>
<lom:lom>
<lom:general>
<lom:title>
<lom:string language="en-US">Title</lom:string>
</lom:title>
</lom:general>
</lom:lom>
</metadata>Code: Select all
$imsmanifest = new DOMDocument;
$imsmanifest->load($manifest_file);
$xpath = new DOMXPath($imsmanifest);
$xpath->registerNamespace("m", http://www.imsglobal.org/xsd/imscp_v1p1);
$query = $xpath->query('/m:manifest/m:organizations/m:organization/m:title');
$title = $query->item(0)->nodeValue;
// This works fine.
$xpath->registerNamespace("lom","http://ltsc.ieee.org/xsd/LOM");
$query = $xpath->query("/lom:string");
$title = $query->item(0)->nodeValue;
// This does not.