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 easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree.  I can add it manually, but I can't figure out how to add it above the root element where PI's are normally placed.  Anyone know how to do this?  I know of plenty of alternative methods of doing it, but it seems that this must be built in somewhere that I just can't find.
Yeah, I don't believe it's possible, sorry. ElementTree provides a simpler interface to (non-namespaced) element-centric XML processing than DOM, but the price for that is that it doesn't support the whole XML infoset.
There is no apparent way to represent the content that lives outside the root element (comments, PIs, the doctype and the XML declaration), and these are also discarded at parse time. (Aside: this appears to include any default attributes specified in the DTD internal subset, which makes ElementTree strictly-speaking a non-compliant XML processor.)
You can probably work around it by subclassing or monkey-patching the Python native ElementTree implementation's write() method to call _write on your extra PIs before _writeing the _root, but it could be a bit fragile.
If you need support for the full XML infoset, probably best stick with DOM.
ElementTree in Python 2.6.2 Processing Instructions support?