Re: [xml] XPath with default namespace



How can I ensure that I have the correct namespaces set up in the context
 before using xPath to query for an element that defines it's namespace
 within that element?
 e.g:
 <xsd:schema targetNamespace="http://namespaces.snowboard-info.com";
       xmlns:xsd="http://www.w3.org/1999/XMLSchema";>

Taking this as a cut down file...

<?xml version="1.0"?>

<definitions name="someservice"
   targetNamespace="http://someserver.com";
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"";>
   <types>
     <xsd:schema targetNamespace="http://namespaces.snowboard-info.com";
       xmlns:xsd="http://www.w3.org/1999/XMLSchema";>
     <xsd:element name="GetEndorsingBoarder"/>
     </xsd:schema>
   </types>
 </definitions>

If I try :
 //definitions/types/xsd:schema/*

XPath returns:
 Error xpath.c:7976: Undefined namespace prefix
 //ofwsdl:definitions/ofwsdl:types/xsd:schema/*
                                               ^
 Error xpath.c:7970: Invalid type
 //ofwsdl:definitions/ofwsdl:types/xsd:schema/*
                                               ^
 Which is obviously because the namespace is not defined yet.

I can hack it by predefining an alternative prefix e.g ofxsd2000 to the URI
 in question but that implies that I have to evaluate a path for each
 possible value of xsd: i.e.

         xmlXPathRegisterNs(ctx, (xmlChar *)"ofxsd2001", (xmlChar
*)"http://www.w3.org/2001/XMLSchema";);
         xmlXPathRegisterNs(ctx, (xmlChar *)"ofxsd2000", (xmlChar
*)"http://www.w3.org/2000/10/XMLSchema";);
         xmlXPathRegisterNs(ctx, (xmlChar *)"ofxsd1999", (xmlChar
*)"http://www.w3.org/1999/XMLSchema";);

and then search with all three possible mappings of xsd to the above URIs.
 Or do I have to walk the tree to the schema element and then load the
 namespaces?

Also, I am unable to figure out how to list out the current namespaces in a
 given context. Any help would be greatly appreciated.

Steve:)







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]