Skip to content

Let XPathContext correctly pick the default namespaceURI #10

@GoogleCodeExporter

Description

@GoogleCodeExporter
[Description]

Since XPathContext tries to retrieve the default namespace URI from the 
document elements' xmlns attribute, it doesn't work in the following situation 
where a) xmlns attribute is modified afterward b) the default namespace URI for 
the document without namespace specifications is implied by the DOM parser.

I was stuck on this in the case (b) because I have a DOM implementation other 
than minidom (actually backed by the WebKit DOM through PyObjC).

Patch attached.

[Code for reproduction]

from xml.dom.minidom import parseString
from xpath import XPathContext

doc = parseString('''
<foo xmlns="http://foo.example.com/">
  <item>foo</item>
  <item xmlns="http://bar.example.com/">bar</item>
</foo>
''')
doc.documentElement.setAttribute('xmlns', 'http://bar.example.com/')
assert doc.documentElement.namespaceURI == 'http://foo.example.com/'
assert doc.documentElement.getAttribute('xmlns') == 'http://bar.example.com/'
nodeset = XPathContext(doc).find('//item', doc)
assert len(nodeset) == 1
assert nodeset[0].namespaceURI == 'http://foo.example.com/' # boom!


[What version of the product are you using? On what operating system?]

SVN head

Original issue reported on code.google.com by m...@mozo.jp on 6 Jan 2013 at 12:09

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions