| Author |
Validating xml against dtd
|
Vishnu Murthy
Ranch Hand
Joined: Jan 04, 2001
Posts: 56
|
|
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
Joined: Mar 09, 2001
Posts: 2676
|
|
|
This topic is more appropriate to the xml forum. I'll move it there for you.
|
Matthew Phillips
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
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.
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
 |
|
|
subject: Validating xml against dtd
|
|
|