lxml.objectify

lxml.objectify and leading zeros

此生再无相见时 提交于 2019-12-24 02:09:11
问题 When the objectify element is printed on the console, the leading zero is lost, but it is preserved in the .text : >>> from lxml import objectify >>> >>> xml = "<a><b>01</b></a>" >>> a = objectify.fromstring(xml) >>> print(a.b) 1 >>> print(a.b.text) 01 From what I understand, objectify automatically makes the b element an IntElement class instance. But, it also does that even if I try to explicitly set the type with an XSD schema: from io import StringIO from lxml import etree, objectify f =

Getting contents of an lxml.objectify comment

不羁的心 提交于 2019-12-12 02:39:08
问题 I have an XML file that I'm reading using python's lxml.objectify library. I'm not finding a way of getting the contents of an XML comment: <data> <!--Contents 1--> <some_empty_tag/> <!--Contents 2--> </data> I'm able to retrieve the comment (is there a better way? xml.comment[1] does not seem to work): xml = objectify.parse(the_xml_file).getroot() for c in xml.iterchildren(tag=etree.Comment): print c.???? # how do i print the contets of the comment? # print c.text # does not work # print str