473,507 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with XML parsing

dmjpro
2,476 Top Contributor
I am trying to parse a XML file with JAXP.
Now what's happening to me ..that ..... the XML file is having some DTD which specifies a site DTD definition ....
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
So right now Connection refused error is coming.
I know why it's coming .... But I want to put off the DTD parsing how could i do that.
One more thing if a DTD is of site then having no net connection validation can't be done ...????
What should be validation code for that .....

Debasis Jana.
Mar 26 '08 #1
7 4162
talonx
18 New Member
I am trying to parse a XML file with JAXP.
Now what's happening to me ..that ..... the XML file is having some DTD which specifies a site DTD definition ....
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
So right now Connection refused error is coming.
I know why it's coming .... But I want to put off the DTD parsing how could i do that.
One more thing if a DTD is of site then having no net connection validation can't be done ...????
What should be validation code for that .....

Debasis Jana.
Turn off validation when you create the DocumentBuilderFactory.
Expand|Select|Wrap|Line Numbers
  1. factory.setValidating(false)
As for your second question, the answer is too complicated to type here :). It involves creating your own Resolver class to serve the dtd from your machine instead of the parser having to connect to the internet.

- talonx
Mar 26 '08 #2
dmjpro
2,476 Top Contributor
Turn off validation when you create the DocumentBuilderFactory.
Expand|Select|Wrap|Line Numbers
  1. factory.setValidating(false)
As for your second question, the answer is too complicated to type here :). It involves creating your own Resolver class to serve the dtd from your machine instead of the parser having to connect to the internet.

- talonx

Thanks for your reply!
I am now having this code ...
Expand|Select|Wrap|Line Numbers
  1.        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  2.        factory.setValidating(false);
  3.        DocumentBuilder jrxml = factory.newDocumentBuilder();
  4.        FileInputStream is = new FileInputStream(file);
  5.        Document jrxml_doc = jrxml.parse(is);
  6.  
Still the error is coming.
What should I do?

Debasis Jana.
Mar 26 '08 #3
r035198x
13,262 MVP
Thanks for your reply!
I am now having this code ...
Expand|Select|Wrap|Line Numbers
  1.        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  2.        factory.setValidating(false);
  3.        DocumentBuilder jrxml = factory.newDocumentBuilder();
  4.        FileInputStream is = new FileInputStream(file);
  5.        Document jrxml_doc = jrxml.parse(is);
  6.  
Still the error is coming.
What should I do?

Debasis Jana.
Which error is coming?
Mar 26 '08 #4
JosAH
11,448 Recognized Expert MVP
Thanks for your reply!
I am now having this code ...
Expand|Select|Wrap|Line Numbers
  1.        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  2.        factory.setValidating(false);
  3.        DocumentBuilder jrxml = factory.newDocumentBuilder();
  4.        FileInputStream is = new FileInputStream(file);
  5.        Document jrxml_doc = jrxml.parse(is);
  6.  
Still the error is coming.
What should I do?

Debasis Jana.
If you had read the API documentation you'd have known that by default that factory
produces non-validating parsers so the error must be somewhere else. Please
read before you start ask questions here and hope that others will do your work
for you. This entire thread has been useless until now because of that non-validating
default behaviour and you simply didn't know that because you haven't read the
API documentation.

kind regards,

Jos
Mar 26 '08 #5
dmjpro
2,476 Top Contributor
If you had read the API documentation you'd have known that by default that factory
produces non-validating parsers so the error must be somewhere else. Please
read before you start ask questions here and hope that others will do your work
for you. This entire thread has been useless until now because of that non-validating
default behaviour and you simply didn't know that because you haven't read the
API documentation.

kind regards,

Jos
Yeah it's OK ......
Connection Refused Exception coming.
It tries to connect that DTD resource .....
How could I solve that?

Debasis Jana
Mar 26 '08 #6
talonx
18 New Member
Yeah it's OK ......
Connection Refused Exception coming.
It tries to connect that DTD resource .....
How could I solve that?

Debasis Jana
Try something like

Expand|Select|Wrap|Line Numbers
  1. documentBuilder.setEntityResolver(resolver);
where resolver is your own custom Resolver class implementing the org.xml.sax.EntityResolver interface. The implementation should read from your local file on disk and return the dtd (or schema). Am sure you can figure out how.

- talonx
Mar 26 '08 #7
dmjpro
2,476 Top Contributor
Try something like

Expand|Select|Wrap|Line Numbers
  1. documentBuilder.setEntityResolver(resolver);
where resolver is your own custom Resolver class implementing the org.xml.sax.EntityResolver interface. The implementation should read from your local file on disk and return the dtd (or schema). Am sure you can figure out how.

- talonx
I need not to check whether it matches with DTD or not .....
I just want to bypass the DTD parsing .
I managed to do that ...by doing this ..
Expand|Select|Wrap|Line Numbers
  1. jrxml.setEntityResolver(new EntityResolver() {
  2.             public InputSource resolveEntity(String publicId, String systemId) throws SAXException,IOException {
  3.                 //return new InputSource("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd");
  4.                 return new InputSource(new ByteArrayInputStream(new byte[0]));
  5.             }
  6.         });
  7.  
Thanks Jos and Thanks Others.
Debasis Jana
Mar 26 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1606
by: Hari Prasad | last post by:
Hi, I am using XMLTool.java to convert an xml file into an xml document and I am parsing the xml file using Nodelist and Nodes. NodeList ls = getElementsByTagName("xxx"). Its working fine when...
7
2180
by: Dennis Roberts | last post by:
I have a script to parse a dns querylog and generate some statistics. For a 750MB file a perl script using the same methods (splits) can parse the file in 3 minutes. My python script takes 25...
12
9747
by: Javier | last post by:
Hello, I'm very new in this forum and as I have the following problem, the website is in http://new.vanara.com ----------------------------------------------------------------------------...
3
1773
by: Eric Lilja | last post by:
Hello, I'm creating a small utility for an online game. It involves parsing a text file of "tradesskill recipes" and inserting these recipes in a gui tree widget (similar to gui file browsers if...
4
1713
by: Hugh | last post by:
Hello, I am having some problems understanding (most likely), parsing a text file. I would like to parse a file like: block1 { stuff; ... stuffN; };
1
3404
by: Chris LaJoie | last post by:
Hi, I have an app that runs many simultaneous threads. I have noticed (took me a while to figure out what it was doing though) that sometimes if there is a problem, the thread will simply...
21
2908
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
15
3642
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
3
1586
by: i80and | last post by:
I'm working on a basic web spider, and I'm having problems with the urlparser. This is the effected function: ------------------------------ def FindLinks(Website): WebsiteLen = len(Website)+1...
13
2787
by: charliefortune | last post by:
I am fetching some product feeds with PHP like this $merch = substr($key,1); $feed = file_get_contents($_POST); $fp = fopen("./feeds/feed".$merch.".txt","w+"); fwrite ($fp,$feed); fclose...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.