[lxml-dev] Removing an attribute
Geoffrey Sneddon
foolistbar at googlemail.com
Sat Jul 5 16:51:19 CEST 2008
On 5 Jul 2008, at 15:38, John W. Shipman wrote:
> 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"/>'
>>>>
>
Ah, simply that. Much thanks.
--
Geoffrey Sneddon
<http://gsnedders.com/>
More information about the lxml-dev
mailing list