File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "validating a DTD in JAVA" Watch "validating a DTD in JAVA" New topic
Author

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
Sheriff

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
Durgaprasad
Greenhorn

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

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

builder.setErrorHandler(new MyErrorHandler());
Document document = builder.parse(new File("books.xml"));
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: validating a DTD in JAVA
 
Similar Threads
xml validation agains xsd
DTD
I need to Java code to validate xml file against dtd
Setting DTD in SAX Parser
path to dtd???xerces1.2.3