[lxml-dev] Handling namespaces in tags

Stefan Behnel stefan_ml at behnel.de
Sat Oct 25 00:45:32 CEST 2008


Hi,

John Krukoff wrote:
> On Fri, 2008-10-24 at 10:50 +0200, Stefan Behnel wrote:
>> Stefan Behnel wrote:
>>>     local_name = etree.QName(someElement.tag).localname
>>>     namespace = etree.QName(someElement.tag).namespace
>> We could even allow passing an Element instead of a tag, such as
>>
>>       local_name = etree.QName(someElement).localname
>>       namespace = etree.QName(someElement).namespace
> 
> Should you decide to give QNames these attributes, and make them
> non-opaque objects, it would also be useful to add a .tag attribute to
> pull the entire formatted name from them. Or at least document the .text
> attribute as doing the same so that it can be depended on.

I'm not sure why Fredrik originally named the attribute "text" instead of
"tag", but my guess is that it's easy to distinguish an Element from something
else (such as an ElementTree) by checking if it has a "tag" attribute. I've
seen code that does this.

Anyway, here's a patch that adds the features above.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qname-properties.patch
Type: text/x-patch
Size: 4123 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20081025/f0f8a0fc/attachment.bin 


More information about the lxml-dev mailing list