[lxml-dev] Removing an attribute
John W. Shipman
john at nmt.edu
Sat Jul 5 16:38:25 CEST 2008
On Sat, 5 Jul 2008, Geoffrey Sneddon wrote:
> Hi,
>
> I can't seem to find any way to totally remove an attribute, short of
> using Element.clear() (which has obvious issues when you just want to
> remove a single attribute). I need to remove at least @id: conformance
> requirements say this must be at least one character, thus just
> setting it to an empty string does not suffice.
>>> from lxml import etree
>>> elt=etree.Element('gi', a1='one', a2='two')
>>> etree.tostring(elt)
'<gi a1="one" a2="two"/>'
>>> del elt.attrib['a2']
>>> etree.tostring(elt)
'<gi a1="one"/>'
>>>
Best regards,
John Shipman (john at nmt.edu), Applications Specialist, NM Tech Computer Center,
Speare 119, Socorro, NM 87801, (505) 835-5950, http://www.nmt.edu/~john
``Let's go outside and commiserate with nature.'' --Dave Farber
More information about the lxml-dev
mailing list