xml:id attribute support

Bug #1503461 reported by Archard Lias
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Invalid
Undecided
Unassigned

Bug Description

Hi,

Is there any way to specify an xml:id="someID" attribute in an lxml etree.Element. As far as I tried I got an exception from:
lxml.etree._attributeValidOrRaise (src/lxml/lxml.etree.c:29439)

when doing either of the two following lines...
e = etree.Element('asd', **{'xml:id': 'asd'}) # throws
e['xml:id'] = 'asd' # for e being a etree.Element. Throws too.

The stacktrace in that case becomes:
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree.Element (src/lxml/lxml.etree.c:68803)()
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree._makeElement (src/lxml/lxml.etree.c:15242)()
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree._makeElement (src/lxml/lxml.etree.c:15125)()
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree._initNodeAttributes (src/lxml/lxml.etree.c:16733)()
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree._addAttributeToNode (src/lxml/lxml.etree.c:17198)()
/usr/lib/python3/dist-packages/lxml/etree.cpython-34m-x86_64-linux-gnu.so in lxml.etree._attributeValidOrRaise (src/lxml/lxml.etree.c:29439)()

Do I need to specify a XML Standard namespace describing the attribute in order to legalize it for lxml? Or is it unintended behavior?

#####
Python : sys.version_info(major=3, minor=4, micro=2, releaselevel='final', serial=0)
lxml.etree : (3, 4, 0, 0)
libxml used : (2, 9, 1)
libxml compiled : (2, 9, 1)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)
#####

Best regards,
~Arlias

Revision history for this message
Archard Lias (archardlias) wrote :

Found the proper way to do it, by specifying {http://www.w3.org/XML/1998/namespace}id as the namespace with the <id> as the value. Probably not the best way to deal with it (not really intended for this I suppose) but works for me.

Changed in lxml:
status: New → Invalid
Revision history for this message
scoder (scoder) wrote :

Yes, this is the correct way to do it.

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.