• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validating a DTD in JAVA

 
Priya Sri
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Durgaprasad
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic