Re: [xml] XPath empty default namespaces (bug?)



On Wed, Oct 31, 2001 at 11:46:25AM -0800, Alex Dron wrote:
Hi,
I'm working on implementation of Canonical XML
(http://www.w3.org/TR/2001/REC-xml-c14n-20010315) and use this library.


  Interesting,

The major problem I bump into is incorrect (IMHO) XPath behavior with empty
default namespaces.
Consider test 3.7 of the URL above, the next XPath expression (evaluated
with namespace declaration xmlns:ietf="http://www.ietf.org";):
----------------------------------------------
(//. | //@* | //namespace::*)
[ self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::e2))
  or
  count(id("E3")|ancestor-or-self::node()) =
count(ancestor-or-self::node())]
----------------------------------------------
against XML:
----------------------------------------------
<!DOCTYPE doc [
<!ATTLIST e2 xml:space (default|preserve) 'preserve'>
<!ATTLIST e3 id ID #IMPLIED>
]>
<doc xmlns="http://www.ietf.org"; xmlns:w3c="http://www.w3.org";>
   <e1>
      <e2 xmlns="">
         <e3 id="E3"/>
      </e2>
   </e1>
</doc>
----------------------------------------------
Should not return <e2> node, but it does! Xerces Xpath works fine with this

  Hum, it could be either:
    - that the e2 node still inherits the default namespace error
    - an XPath error

 1/ is simple to fix
 2/ would be a major pain

  I hope it's 1/ I will loook at it.

example... It adds default attribute, too - libxml doesn't do it by itself,
but I can live with it.

  Do the following before any call to the parser:
    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;

 it will load the DTD and should add defaulted attributes directly in the
tree. the XSLT code does this to follow the XPath spec closely.

Libxml works correctly if I declare additional namespace (i.e
ns="http://somewhere";) using xmlXPathRegisterNs and rewrite XPath expression
as:
----------------------------------------------
(//. | //@* | //namespace::*)
[ self::ietf:e1 or (parent::ietf:e1 and not(self::text() or self::ns:e2))
  or
  count(id("E3")|ancestor-or-self::node()) =
count(ancestor-or-self::node())]
----------------------------------------------

  Okay so it's probably an error building the tree

But it's not workaround for me, because I cannot modify users expressions...
I'm using the latest version of the library. I understand that very few
people will pay attention to the such trifle, but maybe somebody will point
me, whether I could fix it on my own (change sources?) and how feasible it
is...

  I will try to fix it,

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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