File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Why is it not a validating parser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Why is it not a validating parser?" Watch "Why is it not a validating parser?" New topic
Author

Why is it not a validating parser?

James Lee
Ranch Hand

Joined: Oct 16, 2006
Posts: 36
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?

Thanks.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Couple of more things you need to mention.Like it has to validate the xml against a schema and the location of the schema.

Might be useful.


Rahul Bhattacharjee
LinkedIn - Blog
James Lee
Ranch Hand

Joined: Oct 16, 2006
Posts: 36
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.

Thanks.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.
 
jQuery in Action, 2nd edition
 
subject: Why is it not a validating parser?
 
Similar Threads
how to use IBM's XML4J for testing files
validate and parse(print to console) an xml document
parsing confusion
Unable to validate XML against the schema
JAXP1.2 for XML parsing