aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML Parsing error 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 "XML Parsing error" Watch "XML Parsing error" New topic
Author

XML Parsing error

Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
HI

I want to parse XML file
if XML file contains DTD tag then it is unable to parse the file
And of it does not contain any DTD them my prgram is easily able to parse the XML file.

Can any 1 tell me how can I resolve this problem?



if XML file contains DTD then my program throws Exception at Line 11
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
I will never understand why people say "throws Exception" and then leave out the actual exception. My crystal ball is in the shop for the 10,000 vision checkup so I cant read your screen. The whole idea of Java exceptions is to communicate as much as possible what went wrong.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617


My ESPN is out.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Wow, that even looks like me - except I need to get a hat like that!
Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
Following exception is being thrwon
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Check your Internet connection. Your system cannot find the IP address for www.jboss.org. If in doubt, contact your system administrator or ISP.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
is there any way i can skip this DTD validation during parsing
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That probably depends on the parser--but you shouldn't *want* to skip it, it's important. Are you sure it's the correct DTD? Do you have a local library with the DTD in it?
Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
That is the problem I dont have the DTD in my local system and url from i can download the DTD is not working.
That is why i just want to skip the DTD validation.

Actually I am writing a program which parses a JBoss Server login-config.xml file installed on any platform.
So it possible that the server may not be connected to Internet or may not have the DTD locally, at that time when I try to parse the XML file then i am getting the above exception.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

Have you already tried calling DocumentBuilderFactory's setValidating(boolean) method?
Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
I tried it doesnt work
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
One outrageous hack would be to write a custom java.io.InputStream extension which just removes the DTD reference before the parser sees it.

The beauty of Java IO is the ease with which you can do this sort of thing.


Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Anuranjan Arya wrote:That is the problem I dont have the DTD in my local system and url from i can download the DTD is not working.
That is why i just want to skip the DTD validation.

Actually I am writing a program which parses a JBoss Server login-config.xml file installed on any platform.
So it possible that the server may not be connected to Internet or may not have the DTD locally, at that time when I try to parse the XML file then i am getting the above exception.


You seem to have forgotten that a DTD is not only for validation. A DTD can specify entities which may then be used in the document, and it has some other features as well.

I would say your best approach would be to attach an EntityResolver to your parser, and have it return an InputSource containing a local copy of the DTD.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Actually I am writing a program which parses a JBoss Server login-config.xml file installed on any platform.


That is why i just want to skip the DTD validation.


If you are "not" parsing the XML file with its DTD, what are you trying to do? You can't parse without the DTD. You can open the file and read it, but to programatically understand as an XML file, you need the DTD.
Anuranjan Arya
Greenhorn

Joined: Jun 10, 2009
Posts: 17
I am parsing the xml with document builder and later i am getting its content with the help of nodes and child nodes.
And I am successfully able to do that.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Presumably, JBoss servers use that DTD to ensure against configuration errors, so just parsing to a DOM is not sufficient to ensure no errors.

Where do JBoss servers get a copy of that DTD?

A google search for "jboss dtd login config xml" turned up hits dated 2004-2005

Is this even the current JBoss usage?

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

William Brogden wrote:Where do JBoss servers get a copy of that DTD?


I can't speak for JBoss, but I was just reading the Hibernate documentation the other day. Hibernate XML config documents also use a DTD; Hibernate keeps a copy of that DTD in its jar and uses an EntityResolver to resolve references to it. This avoids the hassle of having to go out to an external site to get it and possibly failing to get it.

I wouldn't be surprised to find that JBoss does the same thing. It's a perfectly sensible thing to do and that's why I suggested it in my post a couple of days ago.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Parsing error