Re: [xml] relative xpath matches nodes anywhere in tree

2012-06-06 Thread Daniel Veillard
On Sat, May 26, 2012 at 12:09:09PM -0400, Noam Postavsky wrote:
 On Sat, May 26, 2012 at 8:32 AM, Daniel Veillard veill...@redhat.com wrote:
  On Fri, May 25, 2012 at 06:19:49PM -0400, Noam Postavsky wrote:
  On Fri, May 25, 2012 at 11:38 AM, Daniel Veillard veill...@redhat.com
    xmlXPathNewContext doesn't set the context node, it set it to NULL,
   if you keep it NULL all relative evaluations will fail (which sounds
   the right thing to me at the XPath level) but kind of weird from an
   user point of view, so initializing to the document node sounds the best
   to me.
 
  Sure, but is there a way for a user to discover this, beside asking on
  the mailing list?
 
   Hum, no it's really specific to xmllint, this could be added to the
  man page :-)
 
 Isn't this important info to anyone who uses one of the XPath
 evaluation functions?

  The libxml2 evaluation functions really are following the XPath
specification, the spec really is the defining documentation. The
documentation of an Xpath Context in libxml2
  http://xmlsoft.org/html/libxml-xpath.html#xmlXPathContext
should show the documentation frm the code:

/**
 * xmlXPathContext:
 *
 * Expression evaluation occurs with respect to a context.
 * he context consists of:
 *- a node (the context node) 
 *- a node list (the context node list) 
 *- a set of variable bindings 
 *- a function library 
 *- the set of namespace declarations in scope for the expression 
 * Following the switch to hash tables, this need to be trimmed up at
 * the next binary incompatible release.
 * The node may be modified when the context is passed to libxml2
 * for an XPath evaluation so you may need to initialize it again
 * before the next call.
 */

  I don't know why it wasn't extracted, I guess I need to debug this too!
Also the XPath initialization for xmllint should be documented too,
that's right.

  One of the reasons why that initialization of the context is not
specified in the XPath standard is due to the fact that the standard was
done with the intent to be reused (by XPointer/XLink and XSLT) and we
didnt really expected it to be used as is...

Daniel
-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-06-06 Thread Liam R E Quin
On Wed, 2012-06-06 at 14:51 +0800, Daniel Veillard wrote:

 
   One of the reasons why that initialization of the context is not
 specified in the XPath standard is due to the fact that the standard was
 done with the intent to be reused (by XPointer/XLink and XSLT) and we
 didnt really expected it to be used as is...

It's been improved a lot for XPath 3 - this is one of the reasons the
spec is so much larger, that it has been made more precise.

If you're looking at the xpath stuff in xmllint, by the way, it could
really use an option to bind a URI name to a prefix... (I am too maxed
out to send a patch, I'm sorry - maybe in August)

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/

___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-26 Thread Daniel Veillard
On Fri, May 25, 2012 at 06:19:49PM -0400, Noam Postavsky wrote:
 On Fri, May 25, 2012 at 11:38 AM, Daniel Veillard veill...@redhat.com
   xmlXPathNewContext doesn't set the context node, it set it to NULL,
  if you keep it NULL all relative evaluations will fail (which sounds
  the right thing to me at the XPath level) but kind of weird from an
  user point of view, so initializing to the document node sounds the best
  to me.
 
 Sure, but is there a way for a user to discover this, beside asking on
 the mailing list?

  Hum, no it's really specific to xmllint, this could be added to the
man page :-)

  Actually it is related, because XMLStarlet has the exact same bug as 
  xmllint.
 
   okay, but a priori that's not the same initialization code path, i.e.
  different bug :-)
 
 Except that it was probably copied from xmllint, so it's the same bug :p

 okay :-)

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-26 Thread Noam Postavsky
On Sat, May 26, 2012 at 8:32 AM, Daniel Veillard veill...@redhat.com wrote:
 On Fri, May 25, 2012 at 06:19:49PM -0400, Noam Postavsky wrote:
 On Fri, May 25, 2012 at 11:38 AM, Daniel Veillard veill...@redhat.com
   xmlXPathNewContext doesn't set the context node, it set it to NULL,
  if you keep it NULL all relative evaluations will fail (which sounds
  the right thing to me at the XPath level) but kind of weird from an
  user point of view, so initializing to the document node sounds the best
  to me.

 Sure, but is there a way for a user to discover this, beside asking on
 the mailing list?

  Hum, no it's really specific to xmllint, this could be added to the
 man page :-)

Isn't this important info to anyone who uses one of the XPath
evaluation functions?
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-25 Thread Daniel Veillard
On Fri, May 25, 2012 at 01:44:22AM -0400, Noam Postavsky wrote:
 So apparently when libxml2 evaluates an XPath expression that is
 relative it searches everywhere in the tree, as if the expression
 started with //. For instance
 
 ~/tmp$ cat test.xml
 ?xml version=1.0?
 x
   yTest/y
 /x
 ~/tmp$ xmllint --xpath y test.xml
 yTest/y
 
 My understanding of XPath says that y matches all the child elements
 of the context node named y. Since the context is the root, this
 should match no elements. What's going on here?

  no that really is related to --xpath implementation, if you try it
from the shell you get the right behaviour:

paphio:~/XML - xmllint --shell test.xml
/  xpath y
Object is a Node Set :
Set contains 0 nodes:
/  xpath //y
Object is a Node Set :
Set contains 1 nodes:
1  ELEMENT y
/  

 Actually the error is in --xpath implementation in xmllint :-)

static void doXPathQuery(
   ...
ctxt-node = xmlDocGetRootElement(doc);
res = xmlXPathEval(BAD_CAST query, ctxt);

  here the initialization is done with the Root element instead of
doc itself which is the classic initialization of the context node when
none is specified, leading to the error, just add a z elem child of x and
parent of y and the query will fail:

paphio:~/XML - cat test.xml
?xml version=1.0?
x
  z
yTest/y
  /z
/x

paphio:~/XML - xmllint --xpath y test.xml
XPath set is empty
paphio:~/XML -

  I'm fixing that --xpath node in git :-)

 PS this came up because of an XMLStarlet bug report:
 http://sourceforge.net/tracker/index.php?func=detailaid=3527850group_id=66612atid=515106

  I think that's unrelated :-)

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-25 Thread Noam Postavsky
On Fri, May 25, 2012 at 4:44 AM, Daniel Veillard veill...@redhat.com wrote:
  Actually the error is in --xpath implementation in xmllint :-)

 static void doXPathQuery(
   ...
    ctxt-node = xmlDocGetRootElement(doc);
    res = xmlXPathEval(BAD_CAST query, ctxt);

  here the initialization is done with the Root element instead of
 doc itself which is the classic initialization of the context node when
 none is specified, leading to the error,

Ah, in that case it would be helpful if the documentation mentioned
the correct way to initialize. Using the doc to indicate that the
context is Root seems surprising to me.

 PS this came up because of an XMLStarlet bug report:
 http://sourceforge.net/tracker/index.php?func=detailaid=3527850group_id=66612atid=515106

  I think that's unrelated :-)

Actually it is related, because XMLStarlet has the exact same bug as xmllint.
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-25 Thread Daniel Veillard
On Fri, May 25, 2012 at 10:44:35AM -0400, Noam Postavsky wrote:
 On Fri, May 25, 2012 at 4:44 AM, Daniel Veillard veill...@redhat.com wrote:
   Actually the error is in --xpath implementation in xmllint :-)
 
  static void doXPathQuery(
    ...
     ctxt-node = xmlDocGetRootElement(doc);
     res = xmlXPathEval(BAD_CAST query, ctxt);
 
   here the initialization is done with the Root element instead of
  doc itself which is the classic initialization of the context node when
  none is specified, leading to the error,
 
 Ah, in that case it would be helpful if the documentation mentioned
 the correct way to initialize. Using the doc to indicate that the
 context is Root seems surprising to me.

  The problem is that XPath doesn't define a default value for the
context node. Somehow in XSLT, processing starts at the document node
and that's why I think it makes sense to use this ...

  xmlXPathNewContext doesn't set the context node, it set it to NULL,
if you keep it NULL all relative evaluations will fail (which sounds
the right thing to me at the XPath level) but kind of weird from an
user point of view, so initializing to the document node sounds the best
to me.

  PS this came up because of an XMLStarlet bug report:
  http://sourceforge.net/tracker/index.php?func=detailaid=3527850group_id=66612atid=515106
 
   I think that's unrelated :-)
 
 Actually it is related, because XMLStarlet has the exact same bug as xmllint.

  okay, but a priori that's not the same initialization code path, i.e.
different bug :-)

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


Re: [xml] relative xpath matches nodes anywhere in tree

2012-05-25 Thread Noam Postavsky
On Fri, May 25, 2012 at 11:38 AM, Daniel Veillard veill...@redhat.com
  xmlXPathNewContext doesn't set the context node, it set it to NULL,
 if you keep it NULL all relative evaluations will fail (which sounds
 the right thing to me at the XPath level) but kind of weird from an
 user point of view, so initializing to the document node sounds the best
 to me.

Sure, but is there a way for a user to discover this, beside asking on
the mailing list?

 Actually it is related, because XMLStarlet has the exact same bug as xmllint.

  okay, but a priori that's not the same initialization code path, i.e.
 different bug :-)

Except that it was probably copied from xmllint, so it's the same bug :p
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml


[xml] relative xpath matches nodes anywhere in tree

2012-05-24 Thread Noam Postavsky
So apparently when libxml2 evaluates an XPath expression that is
relative it searches everywhere in the tree, as if the expression
started with //. For instance

~/tmp$ cat test.xml
?xml version=1.0?
x
yTest/y
/x
~/tmp$ xmllint --xpath y test.xml
yTest/y

My understanding of XPath says that y matches all the child elements
of the context node named y. Since the context is the root, this
should match no elements. What's going on here?

PS this came up because of an XMLStarlet bug report:
http://sourceforge.net/tracker/index.php?func=detailaid=3527850group_id=66612atid=515106
___
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml