aspose file tools*
The moose likes XML and Related Technologies and the fly likes Parsing an XML document with an incorrect DTD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing an XML document with an incorrect DTD" Watch "Parsing an XML document with an incorrect DTD" New topic
Author

Parsing an XML document with an incorrect DTD

Archana Mehta Datta
Greenhorn

Joined: Dec 17, 2010
Posts: 8
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?


Archana
For all your days prepare and treat them ever alike, when you are the anvil - bear, when you are the hammer - strike
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Have you tried the javax.xml.parsers.SAXParserFactory setValidating( false ) approach?

Bill
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

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

Joined: Dec 17, 2010
Posts: 8
@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

Joined: Mar 22, 2000
Posts: 12806
    
    5
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
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

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

Joined: Dec 17, 2010
Posts: 8
Thanks Paul, I ended up doing just that and the issue was finally resolved

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Thanks for letting us know, Archana. It's nice to know that sometimes people will do the right thing.
 
Consider Paul's rocket mass heater.
 
subject: Parsing an XML document with an incorrect DTD