Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is it not a validating parser?

 
James Lee
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Lee
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic