[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem parsing XML file with Xerces-J


domparser xerces
What does your EntityResolver actually do?

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Midsummer Sun [mailto:midsummer.sun@g...] 
> Sent: 31 March 2005 11:25
> To: xml-dev@l...
> Subject: Re:  Problem parsing XML file with Xerces-J
> 
> Thanks a lot for your advice. I would like to implement the
> EntityResolver solution.. It seems cleaner object oriented wise ;) Is
> it? or is editing the file using java.io classes(i.e. removing the DTD
> reference) before parsing would be appropriate? Please give your
> advice..
> 
> To my understanding I made the following changes to my program (for
> EntityResolver solution).
> 
> public class XYZ extends DefaultHandler  {
> 
>    public static void main(String[] args)
>    {
>        XYZ obj = new XYZ();
>        
>        try {
>        //XML parser declarations
>        DocumentBuilderFactoryImpl factory = new 
> DocumentBuilderFactoryImpl();
>        DocumentBuilder builder = factory.newDocumentBuilder();
>        builder.setEntityResolver(obj);
> 
>        Document document = builder.parse(new InputSource(new
> StringReader(rsp)));
> 
>        ...... other code
> 
> The program compiles fine. But I am still getting the same error
> (connection timed out)
> 
> Hoping for your further help.
> 
> Best regards,
> 
> 
> On Thu, 31 Mar 2005 10:42:38 +0100, Michael Kay 
> <mike@s...> wrote:
> > The XML parser is trying to access the document at 
> http://host/x.dtd (using
> > the java.net library) and gets a timeout because it isn't 
> accessible.
> > 
> > The fact that you didn't request validation is irrelevant. 
> It's a common,
> > and erroneous, belief that if you don't request validation 
> then the parser
> > won't try to read the external DTD. It needs it to expand 
> entity references.
> > 
> > Try either editing the DTD reference out of the file before 
> parsing it, or
> > using an EntityResolver to satisfy the reference from 
> somewhere else.
> > 
> > Michael Kay
> > http://www.saxonica.com/
> > 
> > 
> > > -----Original Message-----
> > > From: Midsummer Sun [mailto:midsummer.sun@g...]
> > > Sent: 31 March 2005 10:33
> > > To: xml-dev@l...
> > > Subject:  Problem parsing XML file with Xerces-J
> > >
> > > Hi Friends,
> > >    I am parsing a XML file using Xerces-J 2.6.2 using the 
> DOM API. I
> > > am facing some problem. The XML document is available in 
> my program in
> > > Java string form.
> > >
> > > Here is relevant portion of code (with line numbers for
> > > readibility) ..
> > >
> > > 1) DocumentBuilderFactoryImpl factory = new
> > > DocumentBuilderFactoryImpl();
> > > 2) DocumentBuilder builder = factory.newDocumentBuilder();
> > > 3) String rsp = "xmlstring";
> > > 4) Document document = builder.parse(new InputSource(new
> > > StringReader(rsp)));
> > >
> > > A sample xmlstring is (for line 3) -
> > > <?xml version='1.0' encoding='ISO-8859-1'?><!DOCTYPE 
> MESSAGING SYSTEM
> > > 'http://host/x.dtd'><MESSAGING></MESSAGING>
> > >
> > > (I am not using the validating mode. This XML is sent to 
> my program by
> > > a remote process and DTD reference is redundant to me).
> > >
> > > Line 4 is giving error (I am pasting full stack trace for
> > > your reference) -
> > > java.net.ConnectException: Connection timed out: connect
> > >         at java.net.PlainSocketImpl.socketConnect(Native Method)
> > >         at java.net.PlainSocketImpl.doConnect(Unknown Source)
> > >         at 
> java.net.PlainSocketImpl.connectToAddress(Unknown Source)
> > >         at java.net.PlainSocketImpl.connect(Unknown Source)
> > >         at java.net.Socket.connect(Unknown Source)
> > >         at java.net.Socket.connect(Unknown Source)
> > >         at sun.net.NetworkClient.doConnect(Unknown Source)
> > >         at sun.net.www.http.HttpClient.openServer(Unknown Source)
> > >         at sun.net.www.http.HttpClient.openServer(Unknown Source)
> > >         at sun.net.www.http.HttpClient.<init>(Unknown Source)
> > >         at sun.net.www.http.HttpClient.<init>(Unknown Source)
> > >         at sun.net.www.http.HttpClient.New(Unknown Source)
> > >         at sun.net.www.http.HttpClient.New(Unknown Source)
> > >         at sun.net.www.http.HttpClient.New(Unknown Source)
> > >         at
> > > 
> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
> > > ce)
> > >         at
> > > 
> sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
> > >         at
> > > 
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
> > > urce)
> > >         at
> > > 
> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown So
> > > urce)
> > >         at
> > > 
> org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
> > >         at
> > > 
> org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source
> > > )
> > >         at
> > > 
> org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Sourc
> > > e)
> > >         at
> > > 
> org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(
> > > Unknown Source)
> > >         at
> > > 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
> > > known Source)
> > >         at
> > > org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> > >         at
> > > org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> > >         at 
> org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> > >         at 
> org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> > >         at
> > > org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
> > >         at XYZ.main(XYZ.java:47)
> > >
> > > I don't know what this call has to do with java.net package !
> > >
> > > I'll appreciate help in understanding what is going wrong,
> > > and how to solve it..
> > >
> > > Best regards,
> > >
> > > -----------------------------------------------------------------
> > > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> > > initiative of OASIS <http://www.oasis-open.org>
> > >
> > > The list archives are at http://lists.xml.org/archives/xml-dev/
> > >
> > > To subscribe or unsubscribe from this list use the subscription
> > > manager: <http://www.oasis-open.org/mlmanage/index.php>
> > >
> > >
> > 
> >
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
> 
> 



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.