[lxml-dev] Bug: type annotation namespace-prefix goes missing
Christian Zagrodnick
cz at gocept.com
Thu Feb 7 17:16:54 CET 2008
Hi there,
given the following little script:
import lxml.etree
import lxml.objectify
xml = lxml.objectify.XML(
'<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">'
'<b name="b1"><title
py:pytype="str">tit</title><text>foo</text></b><b
name="b2"><text>bar</text></b></a>')
foo = xml['b'][0]
bar = xml['b'][1]
foo['text'] = 'FOO!'
print lxml.etree.tostring(xml, pretty_print=True)
foo = xml.xpath('b[@name="b1"]')[0]
bar = xml.xpath('b[@name="b2"]')[0]
xml['b'] = [bar, foo]
print lxml.etree.tostring(xml, pretty_print=True)
The first print statement prints, where everything is fine:
<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">
<b name="b1">
<title py:pytype="str">tit</title>
<text py:pytype="str">FOO!</text>
</b>
<b name="b2">
<text>bar</text>
</b>
</a>
The second prints:
<a xmlns:py="http://codespeak.net/lxml/objectify/pytype">
<b name="b2">
<text>bar</text>
</b>
<b name="b1">
<title py:pytype="str">tit</title>
<text pytype="str">FOO!</text>
</b>
</a>
Note the last <text node where it says pytype instead of py:pytype.
I think is has something todo with the xpath, but I cannot really
figure out what.
That's with lxml 2.0 and python 2.4
--
Christian Zagrodnick
gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale
www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
More information about the lxml-dev
mailing list