read xml files with namespaces

From: Date: Wed, 28 May 2008 02:02:25 +0000
Subject: read xml files with namespaces
Groups: php.general 
Request: Send a blank email to php-general+get-274756@lists.php.net to get a copy of this message
I am writing code to read a bunch of xml files which describe pharmaceutical drugs. They have namespace references at the top of each file that look like this: <document xmlns:voc="http://www.hl7.org/v3/voc" xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://www.fda.gov/oc/datacouncil/schemas/spl/spl.xsd"> I am having a challenging time coming up with an xpath query that works even after registering a namespace like this: $xpath->registerNamespace("voc","http://www.hl7.org/v3/voc" ); I am trying a query like this: $qry = '//component' ; $nodeList = $xpath->query($qry); I can't seem to make it work. Could someone please advise? thanks Selwyn The whole program looks like this: $dom=new DOMDocument; $dom->load('./828C40F4-5969-4254-9008-36AF15CC601B.xml') ; $qry = '//component' ; $nodeList = $xpath->query($qry); header('Content-Type: text/plain'); foreach ($nodeList as $node) {
    echo $dom->saveXML($node) . "\r\n";
} -- Selwyn Polit Computer Consulting, programming, web sites 512-696-0410 www.AustinProgressiveCalendar.com

« previous php.general (#274756) next »