Page 1 of 1

PHP Xpath with Multiple Namespaces

Posted: Mon Mar 01, 2010 2:34 pm
by kepardue
I'm trying to read a document with the following structure (some stripped out for brevity):

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>
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:

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.
 
 
Is there some issue with using multiple namespaces in the document?

Re: PHP Xpath with Multiple Namespaces

Posted: Mon Mar 01, 2010 4:09 pm
by requinix
The query is wrong. "/lom:string" means the <lom:string> at the root of the document.
That's not where it is.