Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML closing tags missing throws exception with SAX Parser

807580Nov 13 2009 — edited Nov 13 2009
Hey,

I'm trying to create an XML Document from some HTML.

I am getting this exception:
[Fatal Error] :1:334: The element type "input" must be terminated by the matching end-tag "</input>".
Exception in thread "main" java.lang.RuntimeException: org.xml.sax.SAXParseException: The element type "input" must be terminated by the matching end-tag "</input>".
	at server.XMLUtils.createDocument(XMLUtils.java:76)
The xml is like this:
<html>
<input name="s" size="5">
</html>
Is there some setting I can change in the parser to make it ignore missing closing tags?

Here is my current code
	public static Document createDocument(InputStream is) {
		try {
			Document doc;
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			doc = db.parse(is);
			doc.getDocumentElement().normalize();
			is.close();
			return doc;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2009
Added on Nov 13 2009
3 comments
3,441 views