List Info

Thread: Re: Question regarding XPath




Re: Question regarding XPath
country flaguser name
United States
2007-03-16 11:25:45
{{ apologies; I failed to copy the list. }}

On Fri, 16 Mar 2007 08:29:00 -0500, Daniel Veillard
<veillardredhat.com>
wrote:

>   I doubt it, getting 0 nodes really seems an
indication of not getting  
> the
> right binding for the namespaces. And since you don't
indicate what you  
> did
> precisely nor provide the XML target I'm just left
guessing and I hate  
> that
> nearly as much as debugging someone else code.

Sorry for the confusion.

The schema I'm working with is as follows:

<?xml version="1.0"?>
<xs:schema xmlnss=&qu
ot;http://www
.w3.org/2001/XMLSchema">
    <xs:element name="bad-format"
type="empty"/>
</xs:schema>

It's about as simple as it gets.  We use a more complicated
version in our
product, of course.


We parse the document successfully and create a new XPath
context with it:

     xpctxt = xmlNewXPathContext (doc);

We then set the node to be the root of the document and get
the namespace
list:

     xpctxt = xmlDocGetRootElement (doc);
     xpctxt = xmlGetNsList (doc, xpctxt->node);

We iterate through the namespaces, which the debugger
indicates are
properly parsed.  That is, the prefix,href pair
xs,http://www.w3.org/20
01/XMLSchema is found in xpctxt->namespaces.

Following your advice, we then run the XPath query, again
confirmed to be
properly transmitted as "//xs:element" through the
debugger.  This is
stored in the nodeName string:

     xmlXPathObjPtr res = xmlXPathEval (nodeName, xpctxt);

This returns zero nodes.


>   I have seen people in the past trying to use NULL or
"" to registed the
> prefix of XPath queries, there is no way I can try to
guess all error  
> case
> possible.

I do not think this is the case here.  As far as I can tell,
we're setting
up the context correctly with appropriately registered
namespaces and a
properly formatted query.  This XSD and query both worked
with
libxml2-2.6.9.  Our source code hasn't changed.

Now while I am working with a library that I've compiled
from source here,
rather than prebuilt binaries, I have only disabled iconv. 
Every other
option is default, and I cannot imagine that disabling iconv
would be
causing the problem.

>> This isn't terribly complicated, and it looks
pretty similar to what's
>> happening in xpath1.c:
>
>   make sure it's really similar, and check with a
debugger that the
> xmlXPathRegisterNs is called on the right context, and
that the values
> are correct.

I have, actually.  The code from xpath1.c is a copy of the
code from
debugAPI.c, as regards registering the namespaces.  It
parses the strings
exactly the same way and calls the same functions.  That's
why I assume
that the difference lies in the use of xmlXPathEval versus
xmlXPathEvalExpression.


The evaluation code is not trivial to step through (at least
for me, being
somewhat new to libxml2).  I'm still going through it and
trying to
discern where things are getting messed up.  But it looks
like it's
starting out at the right place.


Best,

Ethan



-- 
Objective Systems, Inc.
REAL WORLD ASN.1 AND XML SOLUTIONS
Tel: +1 (484) 875-9841
Fax: +1 (484) 875-9830
Toll-free: (877) 307-6855 (USA only)
http://www.obj-sys.com
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )