• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

validating a DTD in JAVA

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"));
 
reply
    Bookmark Topic Watch Topic
  • New Topic