namespace inconsistency with attributes

Bug #430252 reported by Uwe Hoffmann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Medium
scoder

Bug Description

here is a python session showing a namespace inconsistency (from my
  point of view). It seems that a roundtrip (reading and
  saving a xml document ) is not possible with lxml under this
  circumstances. Maybe there is a misunderstanding on my side.

user at workstation:~/tmp$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml.etree as et
>>> eTree=et.fromstring("""<?xml version="1.0"?>
... <bla xmlns="urn:ns1"
... xmlns:o="urn:ns2"
... xmlns:ns1="urn:ns1"
... >
... <bluff ns1:val="abc"/>
... </bla>
... """)
>>> bluff=eTree.findall("{urn:ns1}bluff")[0]
>>> print bluff.attrib["{urn:ns1}val"]
abc
>>> bluff.attrib["{urn:ns1}val"]="def"
>>> print bluff.attrib["{urn:ns1}val"]
def
>>> #so far everything went well
>>> ts=et.tostring(eTree, xml_declaration=True, encoding="UTF-8")
>>> print ts
<?xml version='1.0' encoding='UTF-8'?>
<bla xmlns="urn:ns1" xmlns:o="urn:ns2" xmlns:ns1="urn:ns1">
  <bluff val="def"/>
</bla>
>>> # val="def" --> attribute namespace was
>>> # lost because of default namespace ?
>>> eTree=et.fromstring(ts)
>>> bluff=eTree.findall("{urn:ns1}bluff")[0]
>>> print bluff.attrib["{urn:ns1}val"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml.etree.pyx", line 1893, in lxml.etree._Attrib.__getitem__
(src/lxml/lxml.etree.c:19259)
KeyError: '{urn:ns1}val'
>>>

it seem that all versions of lxml have this feature (e.g. 2.2.1) and libxml 2.7.2

scoder (scoder)
Changed in lxml:
assignee: nobody → Stefan Behnel (scoder)
importance: Undecided → Medium
milestone: none → 2.3
status: New → Confirmed
Revision history for this message
scoder (scoder) wrote :

Fix implemented in trunk rev. 70310:

https://codespeak.net/viewvc/?view=rev&revision=70310

Changed in lxml:
status: Confirmed → Fix Committed
Revision history for this message
scoder (scoder) wrote :

Fixed in lxml 2.3alpha1.

Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.