Hi folks,
I'm developing a web app that can rely on the browser to automatically
transform XML documents using XSLT. Typically, this is done by
inserting an XML processing instruction into the document. However,
this introduces a slight wrinkle in the structure of lxml (and
elementTree too).
Basically, if I understand the code correctly, the ElementTree class has
a root node that can be accessed through the getRoot method. However,
once I have this node, there is no way to go the next sibling node, at
least not that I can see. Normally, this is fine as typical XML
documents only have a single root. However, when you include PIs, they
actually end up having multiple roots.
For example, this is a valid XML document
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/resources/xslt/blog.xsl"?>
<doc>
<foo>fadsfad</foo>
</doc>
Normally, with libxml2 you create a document, add in the node that
represents "doc", then add in the PI using addPrevSibling or something
like that. When reading in the document, you'll need need to use the
next() function get over the PI.
However, it doesn't appear there is a way to do this in lxml or in
elementTree right now. I've managed to get the PI factory working, I
just can't create multi-rooted documents without a whole lot of mangling
that would break 100% elementTree compatibility -- because as near as I
can tell, elementTree in python subversion can't do this either (or I
haven't figured out how to). It can create PIs, but not put them right
at the beginning of the document before the root not.
Any help on this one?
--Patrick