Finding top-level xml comments using Python ElementTree

I am parsing an xml file using Python ElementTree, for example:

et = ElementTree(file=file("test.xml"))

test.xml begins with a few lines of XML comments.

Is there any way to get these comments from et?

+3
source share
1 answer

For ElementTree 1.2.X, there is an article on Reading Processing Commands and Comments with ElementTree ( http://effbot.org/zone/element-pi.htm ).


EDIT:

An alternative would be to use lxml.etree , which implements the ElementTree API. Quote from compatibility ElementTree lxml.etree :

ElementTree XML, etree .

+4

Source: https://habr.com/ru/post/1703090/


All Articles