Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I parse a document with the DTD?  RSS feed

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that is parsing XML.
I am using the javax.xml.parsers.DocumentBuilder to do the parsing.
The problem I have is the XML contains a referance to a DTD.
I want to parse to the XML without the DTD.
How can I do this?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

Do you mean you want to skip the validation of the document (so don't use the DTD)?
In this case, you can disable the validation as follows:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// disable validation
factory.setValidating(false);

DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("file.xml");

Hope it helps,

Cheers,

Francois
[ May 22, 2008: Message edited by: Francois Dang Ngoc ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!