code: static final DocumentFragment createContent(Document doc, String text) {
  
          // [#150] Text might hold XML content, which can be leniently identified by the presence
          //        of either < or & characters (other entities, like >, ", ' are not stricly XML content)
          if (text != null && (text.contains("<") || text.contains("&"))) {
              DocumentBuilder builder = JOOX.builder();
  
              try {
  
                  // [#128] Trimming will get rid of leading and trailing whitespace, which would
                  // otherwise cause a HIERARCHY_REQUEST_ERR raised by the parser
                  text = text.trim();
  
                  // There is a processing instruction. We can safely assume
                  // valid XML and parse it as such
                  if (text.startsWith("<?xml")) {
                      Document parsed = builder.parse(new InputSource(new StringReader(text)));
                      DocumentFragment fragment = parsed.createDocumentFragment();
                      fragment.appendChild(parsed.getDocumentElement());
  
                      return (DocumentFragment) doc.importNode(fragment, true);
                  }
  
                  // Any XML document fragment. To be on the safe side, fragments
                  // are wrapped in a dummy root node
                  else {
                      String wrapped = "<dummy>" + text + "</dummy>";
                      Document parsed = builder.parse(new InputSource(new StringReader(wrapped)));
                      DocumentFragment fragment = parsed.createDocumentFragment();
                      NodeList children = parsed.getDocumentElement().getChildNodes();
  
                      // appendChild removes children also from NodeList!
                      while (children.getLength() > 0) {
                          fragment.appendChild(children.item(0));
                      }
  
                      return (DocumentFragment) doc.importNode(fragment, true);
                  }
              }
  
              // This does not occur
              catch (IOException ignore) {}
  
              // The XML content is invalid
              catch (SAXException ignore) {}
          }
  
          // Plain text or invalid XML
          return null;
      }
docs: Create some content in the context of a given document
  
  @return <ul>
  <li>A {@link DocumentFragment} if <code>text</code> is
  well-formed.</li>
  <li><code>null</code>, if <code>text</code> is plain text or not
  well formed</li>
  </ul>