This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating xml against dtd

 
Vishnu Murthy
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic is more appropriate to the xml forum. I'll move it there for you.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic