lxml Create XML fragment with no root element?

vannhan

New Member
Is it possible using lxml (or the builtin etree library) to create an object that represents a fragment of xml, but contains two (or more) disjoint trees (i.e. each tree has its own separate root, but they share no common ancestor)?That is, is there anything that could represent the following without creating another element to hold both of them:\[code\]<tree id="A"><anotherelement/></tree><tree id="B"><yetanotherelement/></tree>\[/code\]I can't see anything in the lxml documentation that would allow that, and stackoverflow seems not to have anything directly on point.The use-case here is that I am generating xml programmatically, and the fragments will be assembled into one document for output. I'd like an object I don't need to iterate over/special case, just pass to the lxml methods as if it were a proper tree. (I am aware that such fragments would not of themselves be a complete and correct xml document; I want to store the intermediate products before assembly into such a document).
 
Back
Top