Is it possible to use lxml (or the built-in electronic library) to create an object that represents an xml fragment but contains two (or more) disjoint trees (i.e. each tree has its own separate root, but they do not have a common ancestor)?
That is, is there anything that could represent the following without creating another element to hold both of them:
<tree id="A"><anotherelement/></tree>
<tree id="B"><yetanotherelement/></tree>
I don't see anything in the lxml documentation that would allow this, and stackoverflow doesn't seem to have anything direct to the point.
In this case, I create the xml programmatically, and the fragments will be assembled into a single document for output. I need an object that I don't need to iterate over / special case, just go to lxml methods as if it were a proper tree.
(I know that such fragments by themselves will not be a complete and correct xml document, I want to store intermediate products before assembling into such a document).
source
share