• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validating xml against dtd

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I am new to xml,
I am using DOM parser for xml parsing, before i am going to parse my xml file I want to validating my xml file against the .dtd. could someone tell as how to do this. if possible please give me sample code.
I have written code for parsing xml as below
try{
//Create Document
Document doc = null;
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
File file = new File(XMLFILE);
doc = db.parse(file);
NodeList nl = doc.getElementsByTagName("ITestFrame");
---statements
--statements
--
--
--
}catch(IOException e){
System.out.println("Caught Exception : "+e);
}
here before going for parsing i want check XMLFILE is according to dtd or not.
do we have any method for that.
Thanks
Vishnu
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic is more appropriate to the xml forum. I'll move it there for you.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to call any method for doing the validation -- the parse(...) method does that behind the scenes if you've configured the parser to do validation.
You can use this sample as a base for your DTD validation. You basically need to just drop the ".../validation/schema" feature.
reply
    Bookmark Topic Watch Topic
  • New Topic