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



On Wed, Oct 31, 2001 at 11:46:25AM -0800, Alex Dron wrote:
----------------------------------------------
<!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
example... It adds default attribute, too - libxml doesn't do it by itself,
but I can live with it.

  Well, I can't reproduce this !
First I double checked that e2 is really built in memory with no namespace
associated to it, and this looks right.
Second to test the XPath engine with a namespace context I included it
into an XPointer expression with a single namespace defined:

orchis:~/XML -> cat tst.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>

orchis:~/XML -> cat tst.xpath
xmlns(ietf=http://www.ietf.org)xpointer((//. | //@* | //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())])
orchis:~/XML -> 

If you look at xpointer.c around line 1022, you will see that 
xmlns(ietf=http://www.ietf.org) is directly mapped as a call to
xmlXPathRegisterNs() with the associated prefix and URI.
The xpointer() part will then be evaluated in that context

And the result looks correct:

orchis:~/XML -> ./testXPath --xptr -i tst.xml -f tst.xpath 

========================
Expression: xmlns(ietf=http://www.ietf.org)xpointer((//. | //@* | //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())])
Object is a Node Set :
Set contains 3 nodes:
1  ELEMENT e1
2  ELEMENT e3
    ATTRIBUTE id
      TEXT
        content=E3
3  ATTRIBUTE id
    TEXT
      content=E3
orchis:~/XML ->

  The element e2 is not included in the resulting nodeset, and I don't
understand where your problem comes from. Note that xmlXPathRegisterNs()
is tied to a given evaluation context too, the problem may come from there.

  On a different point, I don't understand why you want to use XPath to
implement canonalization, this looks far too heavy weight and not a good
approach at all from an implementation perspective.

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]