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 Trouble parsing a well-formed file with a defined entity reference 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 "Trouble parsing a well-formed file with a defined entity reference" Watch "Trouble parsing a well-formed file with a defined entity reference" New topic
Author

Trouble parsing a well-formed file with a defined entity reference

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Java 6 and whatever the default XML parser that comes with that. Using htis code,



I'm parsing a well-formed document that begins with



but the parsing always dies with the following exception ...



I'm able to access the DTD URL in a web browser ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"). What else am I doing wrong? Thanks, - Dave
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

The W3C has been refusing to serve that DTD for years now because it was disgusted by undisciplined applications (many written in Java) which didn't bother to cache it. Chances are that the error is occurring because of that.

So... where are you trying to get it from? Do you have an XML catalog configured, or something like that?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The PUBLIC identifier of a DOCTYPE declaration is for informational purposes. I would removed the DOCTYPE declaration and confirm that the file is well-formed. You could used the XML parser of the Internet Explorer by simply navigating to the file. If the file is well-formed you will be able to view the markup and the contents. Or, you could parse the document using an XML parser such as XP.

XP - an XML Parser in Java
www.jclark.com/xml/xp/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

But removing the DOCTYPE would make any entities declared in that DTD (like   for example) become not well-formed, wouldn't it?
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi Paul, I don't quite know how the parser works, but as far as I know, it is trying to get the DTD directly from the Internet, so your explanation about the W3C blocking access makes sense with what's happening. Is there a way to tell the parser to ignore resolving entities or some other work-around?

Jimmy, Using your suggestion, I confirmed that the document is well-formed. Would the parser you suggest overcome the problems that Paul mentioned? - Dave
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Ah, I found out how to turn off DTD resolving, described here -- http://rubenlaguna.com/wp/2009/10/25/disable-dom-dtd-validation/index.html/ .

Now this problem is a laughable thing of the past, like RC Cola or the Simple Life. - Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble parsing a well-formed file with a defined entity reference