I\'m trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easil
With the lxml API it couldn't be easier, though it is a bit "underdocumented":
If you need a top-level processing instruction, create it like this:
from lxml import etree
root = etree.Element("anytagname")
root.addprevious(etree.ProcessingInstruction("anypi", "anypicontent"))
The resulting document will look like this:
They certainly should add this to their FAQ because IMO it is another feature that sets this fine API apart.