Hi,
 
I have been successfully using XPath to parse some data from my XML docs for
quite a while. Now I have a document that uses namespaces. And I can't get a
grip on how to address my data any more. Does anyone know how to solve the
following problem? Any help appreciated.
 
Cheers,
André
([EMAIL PROTECTED])
 
<?php
 
// no namespaces - no trouble
$xml1 = '<?xml version="1.0" encoding="UTF-8"?>'.
        '<ITCL type="TestDefinition" />';
$dom1 = domxml_open_mem($xml1);
$xpc1 = xpath_new_context($dom1);
$attrib1 = xpath_eval($xpc1, "/ITCL/@type");
$type1 = $attrib1->nodeset[0]->value;
print "Type1: $type1\n";
 
// using namespaces I am lost
// without the "xmlns" attribute, this also works fine
$xml2 = '<?xml version="1.0" encoding="UTF-8"?>'.
        '<ITCL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";'
<http://www.w3.org/2001/XMLSchema-instance%22'> .
        ' xsi:schemaLocation="http://api.imbp.de/schema/xsd/itcl'
<http://api.imbp.de/schema/xsd/itcl'> .
        ' http://api.imbp.de/schema/xsd/itcl";'
<http://api.imbp.de/schema/xsd/itcl%22'> .
        ' xmlns="http://api.imbp.de/schema/xsd/itcl";'
<http://api.imbp.de/schema/xsd/itcl%22'> .
        ' type="TestDefinition" />';
$dom2 = domxml_open_mem($xml2);
$xpc2 = xpath_new_context($dom2);
$attrib2 = xpath_eval($xpc2, "/ITCL/@type");
$type2 = $attrib2->nodeset[0]->value;
print "Type2: $type2\n";
 
?>
 

Reply via email to