[lxml-dev] smart_strings

Hi, I would like to know if exists a way to reach an attribute name with an xpath result from _ElementStringResult instance. I see that we can reach is parent, but i need to know to which attribute this result belong, without parsing xpath expression with regex or something similar. root = etree.XML('<root><a a="aaa">TEXT</a></root>') result = root.xpath('/root/a/attribute::a')[0] assert result.is_attribute result.getparent().???? Regards, Nicolas -- Nicolas Delaby Nexedi: Consulting and Development of Libre / Open Source Software http://www.nexedi.com/

Nicolas Delaby, 21.11.2009 16:34:
I would like to know if exists a way to reach an attribute name with an xpath result from _ElementStringResult instance. I see that we can reach is parent, but i need to know to which attribute this result belong, without parsing xpath expression with regex or something similar.
root = etree.XML('<root><a a="aaa">TEXT</a></root>') result = root.xpath('/root/a/attribute::a')[0] assert result.is_attribute result.getparent().????
You'll have to wait for lxml 2.3 (or use the current SVN trunk), which will provide the smart string results of attributes with an "attrname" property. Stefan

Stefan Behnel a écrit :
Nicolas Delaby, 21.11.2009 16:34:
I would like to know if exists a way to reach an attribute name with an xpath result from _ElementStringResult instance. I see that we can reach is parent, but i need to know to which attribute this result belong, without parsing xpath expression with regex or something similar.
root = etree.XML('<root><a a="aaa">TEXT</a></root>') result = root.xpath('/root/a/attribute::a')[0] assert result.is_attribute result.getparent().????
You'll have to wait for lxml 2.3 (or use the current SVN trunk), which will provide the smart string results of attributes with an "attrname" property.
Stefan
This is a good news, I'll be patient :) Thanks, Nicolas -- Nicolas Delaby Nexedi: Consulting and Development of Libre / Open Source Software http://www.nexedi.com/
participants (2)
-
Nicolas Delaby
-
Stefan Behnel