OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Problem parsing XML file with Xerces-J

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Re: [xml-dev] Problem parsing XML file with Xerces-J
  • From: Midsummer Sun <midsummer.sun@gmail.com>
  • Date: Thu, 31 Mar 2005 15:54:50 +0530
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=h5Ld2fQvODp38eOJ2l+BgEpcn6UNOabXxIs5b+GXK9+jYajEehDgfll9FQoNkHIJ2SnUiEnsDCOwLE4v6phdq936AHeaYr96k/oyrlRudhTUdkE2z9Gu28X4UyT3HRJISzkAu2cSjnYwUDZQVNVpLxkZSBHSBHNR2yOGtrsglXU=
  • In-reply-to: <424bc615.0f6e52f5.1290.7da2SMTPIN_ADDED@mx.gmail.com>
  • References: <bb5e8b860503310132279670ba@mail.gmail.com> <424bc615.0f6e52f5.1290.7da2SMTPIN_ADDED@mx.gmail.com>
  • Reply-to: Midsummer Sun <midsummer.sun@gmail.com>

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@saxonica.com> 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@gmail.com]
> > Sent: 31 March 2005 10:33
> > To: xml-dev@lists.xml.org
> > Subject: [xml-dev] 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>
> >
> >
> 
>




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS