hi all, Can anyone tell me how can i validate xml file against DTD/Schema using DOM or jDOM? I mean to say that user will provide me the path of the xml file to parse, I will validate that xml file using the DTD/Schema i have. My Question is how can i validate that XML file against the DTD/Schema i have. Please provide code or any tutorial from internet. Please reply ASAP. Thanks and Regards [ April 05, 2004: Message edited by: Ali Gohar ]
/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
The bad thing is, as far as I know, that you cannot validate a in-memory DOM element. This feature only come with DOM 3. So if you have an DOM argument, you have to serialize it before validating its XSD compliance (Lasse, please correct me if I am wrong)
Joined: Jan 23, 2002
Originally posted by Jean-Louis Marechaux: The bad thing is, as far as I know, that you cannot validate a in-memory DOM element.
I guess this is true. There is no in-memory implementation of InputSource that you could pass on to DocumentBuilder#parse()... Although you could try to write such a class.
Joined: Mar 18, 2004
Thank you all of you. But my question was that how can i validate the XML file supplied by user against the Schema file that i have. I mean lets suppose i have set the Features. But there isn't any Schema file i have supplied it will validate against the Schema file supplied in that XML file.Isn't it? Can i validate the file using the Schema that i have, Not provided by the user. User will only provide the XML Document. Is it possible? Once again thanks for all of you. [ April 05, 2004: Message edited by: Ali Gohar ]
Originally posted by Ali Gohar: Can i validate the file using the Schema that i have, Not provided by the user. User will only provide the XML Document. Is it possible?
We have an example at our wiki (although the page in question is currently not rendered correctly) where you can specify an "external schema document" to validate against using Xerces-specific properties. There's also a very nice article by Elliotte Rusty Harold at InformIT.com about the subject. If (when) you're able to use JAXP 1.2, you can also use a standard mechanism for telling the parser where to find the schema document.
Joined: Nov 12, 2001
The way to specify an external schema is something like that :