473,659 Members | 2,934 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.s ourceforge.net/dtds/jasperreport.dt d">
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 4170
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.s ourceforge.net/dtds/jasperreport.dt d">
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 DocumentBuilder Factory.
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 DocumentBuilder Factory.
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.Ent ityResolver 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.Ent ityResolver 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
1613
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 I am running my application in windows. But when I am running the same application in unix, I am getting exceptions while parsing. Its giving null value and I cannot proceed further.
7
2200
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 minutes. It is enough of a difference that unless I can figure out what I did wrong or a better way of doing it I might not be able to use python (since most of what I do is parsing various logs). The main reason to try python is I had to look at...
12
9775
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 ---------------------------------------------------------------------------- -------------------------------------------- Here's how the site works: You should press a button in the rollover area in order to load a source file on an Iframe, this Iframe is actually hidden working as a Buffer. The body of this loaded Iframe is...
3
1787
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 you know what I mean). Here's an example of a recipe as it appears in the text file: * Cashew Pie (lvl 39, 5h 3 min, + max power) - Candied Cashew (level 30) -- Cashew -- Refined Honey (level 30) --- Raw Honey
4
1721
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
3410
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 terminate on the line that caused a simple exception, but does not throw any error or inform me in any way. I recently found one of these problems in a function that does an int.Parse(string), however, there are many more. I was apparently wrong in...
21
2934
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
15
3656
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
3
1597
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 CurrentLink = '' i = 0 SpliceStart = 0 SpliceEnd = 0
13
2821
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 ($fp); and then parsing them with PHP's native parsing functions. This is succesful for most of the feeds, but a couple of them claim to be
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
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 we have to send another system

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.