You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by "Ray, William N" <wi...@lmco.com> on 2009/04/29 19:22:08 UTC

xpath namespace specification

Hi,

 

I have the following xml file:

 

<?xml version="1.0" encoding="UTF-8"?>

<dgf:test xmlns:dgf="http://tt">

            <dgf:test1>10</dgf:test1>

</dgf:test>

 

I'm trying to select the test1 node.

 

When I run SimpleXPathCAPI and pass in the aforementioned xml file and
this xpath: /test/test1

I do not get any results.

 

When I run SimpleXPathCAPI and pass in the aforementioned xml file and
this xpath: /dgf:test/dgf:test1

I get an error code 12

 

Is there something wrong with how I've defined my xml file?  Does the
SimpleXPathCAPI sample handle specifying the namespace of a node in the
xpath expression?  If not, how would I go about being able to select the
node I'm trying to select?

 

Thanks 


Re: xpath namespace specification

Posted by David Bertoni <db...@apache.org>.
Ray, William N wrote:
> Hi,
> 
> I have the following xml file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <dgf:test xmlns:dgf="http://tt">
>             <dgf:test1>10</dgf:test1>
> </dgf:test>
> 
> I’m trying to select the test1 node.
> 
> When I run SimpleXPathCAPI and pass in the aforementioned xml file and 
> this xpath: /test/test1
> 
> I do not get any results.
Yes, because your document contains elements in a particular namespace, 
and your XPath expression is looking for elements that are not in a 
namespace.


> When I run SimpleXPathCAPI and pass in the aforementioned xml file and 
> this xpath: /dgf:test/dgf:test1
> 
> I get an error code 12
> 
> Is there something wrong with how I’ve defined my xml file?  Does the 
> SimpleXPathCAPI sample handle specifying the namespace of a node in the 
> xpath expression?  If not, how would I go about being able to select the 
> node I’m trying to select?
Unfortunately, the C API has no mechanism for resolving namespace 
prefixes.  You can use SimpleXPathAPI, which uses the C++ APIs, and 
implements a simple method for resolving namespace prefixes by examining 
the root element for namespace declarations.

If you need similar functionality in C, please file an enhancement 
request in Jira:

http://issues.apache.org/jira/browse/XALANC

Dave