I am using cElementTree
library to produce xml files. Now I want to write .xsl
file for better readability. That's why I need to add <?xml-stylesheet type="text/xsl" href="style.xsl"?>
before first tag. Unfortunately I was able to put desired line only after first tag:
import xml.etree.cElementTree as Et
test_report = Et.Element("TEST_REPORT")
root = test_report
root.append(Et.ProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="style.xsl"'))
...
...
tree = Et.ElementTree(root)
tree.write(self.file_name+"_result.xml")
Witch logically produces:
<TEST_REPORT>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
...
...
</TEST_REPORT>
What I need is:
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<TEST_REPORT>
...
...
</TEST_REPORT>
I am looking for something like this but it seems like there is no addprevious
method in cElementTree.