title: lxml Create XML fragment with no root element?
body: <p>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)?</p>
  
  <p>That is, is there anything that could represent the following without creating another element to hold both of them:</p>
  
  <pre><code>&lt;tree id="A"&gt;&lt;anotherelement/&gt;&lt;/tree&gt;
  &lt;tree id="B"&gt;&lt;yetanotherelement/&gt;&lt;/tree&gt;
  </code></pre>
  
  <p>I can't see anything in the lxml documentation that would allow that, and stackoverflow seems not to have anything directly on point.</p>
  
  <p><strong>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.</strong> </p>
  
  <p>(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).</p>