how to read comment before the root element of xml python 1

how to read comment before the root element of xml python

>>> from lxml import etree
>>> tree = etree.parse('filename.xml')
>>> root = tree.getroot()
>>> print root.getprevious()

Here is what the above code is Doing:
1. We import the etree module from the lxml package.
2. We parse the XML file and store the resulting tree in a variable called tree.
3. We get the root element of the tree and store it in a variable called root.
4. We print the previous sibling of the root element.

Similar Posts