title: How to parse a DocumentFragment with with the Java standard DOM API
body: <p>This is how I can parse a well-formed XML document in Java:</p>
  
  <pre class="lang-java prettyprint-override"><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  
  // text contains the XML content
  Document doc = builder.parse(new InputSource(new StringReader(text)));
  </code></pre>
  
  <p>An example for text is this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;a&gt;
    &lt;b/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>How can I parse a DocumentFragment? For example, this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;a&gt;
    &lt;b/&gt;
  &lt;/a&gt;
  &lt;a&gt;
    &lt;b/&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>NOTE: I want to use <code>org.w3c.dom</code> and no other libraries/technologies, if possible.</p>