Javax xml parser stuck when building from HTTP input stream <p>I'm trying to open an HTTP connection to a website and parse the html into a <code>org.w3c.dom.Document</code> class. I can open the HTTP connection and output the webpage to the console just fine, but if I pass the InputStream object to the XML parser, it hangs for a minute and outputs the error</p> <pre><code>[Fatal Error] :108:55: Open quote is expected for attribute "{1}" associated with an element type "onload". </code></pre> <p>Code: </p> <pre><code>private static Document getInputStream(String url) throws IOException, SAXException, ParserConfigurationException { System.out.println(url); URL webUrl = new URL(url); URLConnection connection = webUrl.openConnection(); connection.setConnectTimeout(60 * 1000); connection.setReadTimeout(60 * 1000); InputStream stream = connection.getInputStream(); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(stream); // This line is hanging return doc; } </code></pre> <p>Stack trace when paused:</p> <pre><code>Thread [main] (Suspended) SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method] SocketInputStream.read(byte[], int, int) line: not available BufferedInputStream.fill() line: not available BufferedInputStream.read1(byte[], int, int) line: not available BufferedInputStream.read(byte[], int, int) line: not available HttpClient.parseHTTPHeader(MessageHeader, ProgressSource, HttpURLConnection) line: not available HttpClient.parseHTTP(MessageHeader, ProgressSource, HttpURLConnection) line: not available HttpURLConnection.getInputStream() line: not available XMLEntityManager.setupCurrentEntity(String, XMLInputSource, boolean, boolean) line: not available XMLEntityManager.startEntity(String, XMLInputSource, boolean, boolean) line: not available XMLEntityManager.startDTDEntity(XMLInputSource) line: not available XMLDTDScannerImpl.setInputSource(XMLInputSource) line: not available XMLDocumentScannerImpl$DTDDriver.dispatch(boolean) line: not available XMLDocumentScannerImpl$DTDDriver.next() line: not available XMLDocumentScannerImpl$PrologDriver.next() line: not available XMLNSDocumentScannerImpl(XMLDocumentScannerImpl).next() line: not available XMLNSDocumentScannerImpl.next() line: not available XMLNSDocumentScannerImpl(XMLDocumentFragmentScannerImpl).scanDocument(boolean) line: not available XIncludeAwareParserConfiguration(XML11Configuration).parse(boolean) line: not available XIncludeAwareParserConfiguration(XML11Configuration).parse(XMLInputSource) line: not available DOMParser(XMLParser).parse(XMLInputSource) line: not available DOMParser.parse(InputSource) line: not available DocumentBuilderImpl.parse(InputSource) line: not available DocumentBuilderImpl(DocumentBuilder).parse(InputStream) line: not available MSCommunicator.getInputStream(String) line: 45 MSCommunicator.getGamePageFromForum(int, int, int) line: 70 MSCommunicator.getGamePageFromForum(int, int) line: 57 Game.&lt;init&gt;(int, int) line: 21 MSCommunicator.main(String[]) line: 26 </code></pre>