lxml:objectify: data type of attribute

is there any way to specify the data type of an attribute? Seems like its always string. -- ambiHome GmbH Theaterstr. 19 52062 Aachen Tel +49-241-5380948-3 Fax +49-241-5380948-9 info@ambiHome.de Gesellschaft mit beschränkter Haftung Amtsgericht Aachen, HRB 15813 USt-IdNr. DE268539526 Geschäftsführung: Dipl.-Ing. Roman Wienert

Hi,
Yes, attributes are just (unicode) strings. Unlike lxml.objectify elements which behave like Python builtin datatypes for most practical applications. lxml elements are basically Python proxy elements representing the underlying XML tree (text). If you read up on how objectify matches datatypes (http://lxml.de/objectify.html#how-data-types-are-matched) you'll notice the use of certain type annotation attributes that are relevant to the type lookup. This is e.g. relevant if you do s.th. like
As XML attributes can't themselves carry attributes, as opposed to elements, this scheme isn't directly applicable to attributes. Hence, those are just strings. That said, you may be able to hook custom element classes into lxml that provide you with a similar type lookup scheme for the elem.get()/set()/attrib() stuff, if you don't care about elem.set('attr_a', '5') being returned as elem.get('attr_a') -> 5 [int] or the like. lxml.objectify's classes are themselves just (lxml-batteries-included ;-)) custom element classes. (Haven't tried it out, see http://lxml.de/element_classes.html for background) Holger

Hi,
Yes, attributes are just (unicode) strings. Unlike lxml.objectify elements which behave like Python builtin datatypes for most practical applications. lxml elements are basically Python proxy elements representing the underlying XML tree (text). If you read up on how objectify matches datatypes (http://lxml.de/objectify.html#how-data-types-are-matched) you'll notice the use of certain type annotation attributes that are relevant to the type lookup. This is e.g. relevant if you do s.th. like
As XML attributes can't themselves carry attributes, as opposed to elements, this scheme isn't directly applicable to attributes. Hence, those are just strings. That said, you may be able to hook custom element classes into lxml that provide you with a similar type lookup scheme for the elem.get()/set()/attrib() stuff, if you don't care about elem.set('attr_a', '5') being returned as elem.get('attr_a') -> 5 [int] or the like. lxml.objectify's classes are themselves just (lxml-batteries-included ;-)) custom element classes. (Haven't tried it out, see http://lxml.de/element_classes.html for background) Holger
participants (2)
-
jholg@gmx.de
-
Sebastian Fey, ambiHome GmbH