Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes XML and Related Technologies and the fly likes validating a DTD in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "validating a DTD in JAVA" Watch "validating a DTD in JAVA" New topic

validating a DTD in JAVA

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi friends,

I am using DOM parser to parse an XML in Java. Now, I want to validate this XML using an external DTD(by specifying the DTD file name in java not specifying in XML file) before parsing the XML.

Please guide me abt how to do that validation of XML that it conforms to the DTD given in java.

Thanks in Advance.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Priya Sri,

Please take some time to pick the correct forum for you question.
This forum is for servlet questions.
Moving to our XML and Related Technologies forum.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf

Joined: Oct 02, 2006
Posts: 17
HOpe the following code will help you

//parser.parse(new File(filename), handler);
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder =builderFactory.newDocumentBuilder();

builder.setErrorHandler(new MyErrorHandler());
Document document = builder.parse(new File("books.xml"));
I agree. Here's the link:
subject: validating a DTD in JAVA
It's not a secret anymore!