This code is supposed to create a validating parser:
When I used the parser to parse an xml file, it didn't validate tags in the file, which means the parser is not a validating parser. What's wrong here? Do I miss anything? Should I change the SAXParserFactory implementation class?
Thank you, Rahul. I use a DTD to specify valid tags in the xml file I want to parse, like this: In the xml file, I put a tag which is not declared in the DTD file on purpose. When I used the parser to parse the file, the parser didn't find that tag is invalid.
Joined: Nov 29, 2005
If the DTD is embedded in the xml then a simple parse would do the validation.I would suggest you to use a EntityResolver and to put URL of DTD in xml and plug the EntityResolver in the parser,so while parsing the parser would use the EntityResolver to resolve the URI to a DTD in the local file system.