title: Java Convert InputStream of XML to Document object always results in NULL
body: <p>I am trying to parse a XML string into <code>org.w3c.dom.Document</code> object. </p>
  
  <p>I have looked at solutions provided <a href="https://stackoverflow.com/questions/8484921/how-to-convert-string-to-dom-document-object-in-java">here</a>, <a href="https://stackoverflow.com/questions/7607327/how-to-create-a-xml-object-from-string-in-java">here</a> and a few other blogs that give a variation of the same solution. But the <code>Document</code> object's #Document variable is always null and nothing gets parsed. </p>
  
  <p>Here is the XML file</p>
  
  <pre><code> XMLMappingValidator v = new XMLMappingValidator("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n" +
  "&lt;mapping&gt;\n" +
  "&lt;container&gt;\n" +
  "&lt;source-container&gt;c:\\stem.csv&lt;/source-container&gt;\n" +
  "&lt;source-type&gt;CSV_FILE&lt;/source-type&gt;\n" +
  "&lt;target-container&gt;db&lt;/target-container&gt;\n" +
  "&lt;target-type&gt;MySQL_TABLE&lt;/target-type&gt;\n" +
  "&lt;/container&gt;\n" +
  "&lt;entity&gt;\n" +
  "&lt;source-entity&gt;stem&lt;/source-entity&gt;\n" +
  "&lt;target-entity&gt;tbl_stem&lt;/target-entity&gt;\n" +
  "&lt;/entity&gt;\n" +
  "&lt;attributes&gt;\n" +
  "&lt;attribute&gt;\n" +
  "&lt;datatype&gt;SMALLINT&lt;/datatype&gt;\n" +
  "&lt;source-attribute&gt;id&lt;/source-attribute&gt;\n" +
  "&lt;target-attribute&gt;id&lt;/target-attribute&gt;\n" +
  "&lt;/attribute&gt;\n" +
  "&lt;attribute&gt;\n" +
  "&lt;datatype&gt;VARCHAR&lt;/datatype&gt;\n" +
  "&lt;source-attribute&gt;name&lt;/source-attribute&gt;\n" +
  "&lt;target-attribute&gt;name&lt;/target-attribute&gt;\n" +
  "&lt;/attribute&gt;\n" +
  "&lt;attribute&gt;\n" +
  "&lt;datatype&gt;TEXT&lt;/datatype&gt;\n" +
  "&lt;source-attribute&gt;body&lt;/source-attribute&gt;\n" +
  "&lt;target-attribute&gt;body&lt;/target-attribute&gt;\n" +
  "&lt;/attribute&gt;\n" +
  "&lt;attribute&gt;\n" +
  "&lt;datatype&gt;DATETIME&lt;/datatype&gt;\n" +
  "&lt;source-attribute&gt;date&lt;/source-attribute&gt;\n" +
  "&lt;target-attribute&gt;date&lt;/target-attribute&gt;\n" +
  "&lt;/attribute&gt;\n" +
  "&lt;attribute&gt;\n" +
  "&lt;datatype&gt;VARCHAR&lt;/datatype&gt;\n" +
  "&lt;source-attribute&gt;info&lt;/source-attribute&gt;\n" +
  "&lt;target-attribute&gt;info&lt;/target-attribute&gt;\n" +
  "&lt;/attribute&gt;\n" +
  "&lt;/attributes&gt;\n" +
  "&lt;/mapping&gt;");
  </code></pre>
  
  <p>The constructor XMLMappingValidator object's code is as follows</p>
  
  <pre><code>public class XMLMappingValidator {
      private  Document xml;
      public XMLMappingValidator (String xmlString) throws 
              IOException, SAXException, ParserConfigurationException {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
          DocumentBuilder builder = factory.newDocumentBuilder();  
          this.xml = 
                  builder.parse(new InputSource(new StringReader(xmlString)));          
      }
  
      public Document getXML() {
          return xml;
      }
  }
  </code></pre>
  
  <p>When I call <strong>v.getXML().toString()</strong> I get <code>[#document: null]</code></p>
  
  <p>Clearly, the parse is failing. But I don't understand why. </p>
  
  <p>Any suggestions/help is greatly appreciated.</p>