Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic