title: Ignore org.xml.sax.SAXParseExceptions when transfer xml string to org.w3c.dom.Document?
body: <p>I have a lot of html pages (I mean its source codes) represented like java.Util.List of Strings in Java. I need to convert it to Document objects in Java (from the package org.w3c.dom).</p>
  
  <p>I do it this way with DocumentBuilderFactory and Document:</p>
  
  <pre><code>public static org.w3c.dom.Document inputStream2Document(InputStream inputStream) throws IOException, SAXException, ParserConfigurationException {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setValidating(false);
      org.w3c.dom.Document parse = dbf.newDocumentBuilder().parse(inputStream);
      return parse;
  }   
  </code></pre>
  
  <p>Some of the pages are transformed the right way but there is a problem that there are some other pages with for example wrong written attributes and it is not valid (attributes without ="" ... so it looks like </p>
  
  <pre><code>&lt;a href="somepage.html" someattr&gt;
  </code></pre>
  
  <p>for wrong written attribut called "someattr"). And in this cases I get exceptions, for example</p>
  
  <pre><code>Nested exception: org.xml.sax.SAXParseException; lineNumber: 7558; columnNumber: 71; Element type "a" must be followed by either attribute specifications, "&gt;" or "/&gt;".
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Nested exception: org.xml.sax.SAXParseException; lineNumber: 109; columnNumber: 32; The string "--" is not permitted within comments.
  </code></pre>
  
  <p>Is there any way to say to DocumentBuilderFactory that he should ignore this exceptions? I want to convert these pages to Document too and I do not mind that they are not valid.</p>