Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing an XML document with an incorrect DTD

 
Archana Mehta Datta
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to parse an XML document which refers a DTD that further refers to other DTDs. The issue is that one of those second step DTDs is ill-formed, but I don't have the rights to change it. How can I force the SAX reader to read the XML, ignoring the DTD issues?
Will the SAXON parser also give issues while transforming this XML? If yes,then how can I avoid that?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the javax.xml.parsers.SAXParserFactory setValidating( false ) approach?

Bill
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an XML document which refers a DTD that further refers to other DTDs


Please explain how a XML DTD refers to other DTDs.
 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My approach would be to get the malformed DTD fixed. Just because you personally don't have the authority to make the change, doesn't mean it can't be done.

And there's no such thing as "the SAXON parser". Saxon just uses whatever XML parser the JVM is configured to use.
 
Archana Mehta Datta
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@William- Yes, I tried that, but despite setting it to false, it kept on validating the DTD.

@Paul- Thanks for the correction Correcting the DTD is just not an option for me, I am way down the hierarchy.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about creating a copy of the XML document with the original DTD reference removed or changed to point to a correct one?

Bill
 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Archana Mehta Datta wrote: Correcting the DTD is just not an option for me, I am way down the hierarchy.


What you have to do is to say "That XML couldn't be parsed because the DTD is incorrect". Keep saying it until somebody figures out that the DTD is incorrect.
 
Archana Mehta Datta
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, I ended up doing just that and the issue was finally resolved

 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for letting us know, Archana. It's nice to know that sometimes people will do the right thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic