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: Michael Kay <mike@saxonica.com>
  • Subject: Re: [xml-dev] Problem parsing XML file with Xerces-J
  • From: Midsummer Sun <midsummer.sun@gmail.com>
  • Date: Thu, 31 Mar 2005 16:37:25 +0530
  • Cc: xml-dev@lists.xml.org
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=HTRrBMbV7v7x7aiRg0ORT4rcozN41gNdkk/4VHKBqGVsv8nnGpCsy4voKsaFljYdNQ9ks/awvMwS0xWcTxIxva4TO/2P9TXjJ3XhmaJzGltzwgbjEHW1PmK/3+Z7xkNMu1bGxLRSUalyPTvue3b3zpWZDVEhPc+QiynivCUFCuA=
  • In-reply-to: <424bd441.1e7d4a1f.35e0.ffffb215SMTPIN_ADDED@mx.gmail.com>
  • References: <bb5e8b8605033102246096e3ed@mail.gmail.com> <424bd441.1e7d4a1f.35e0.ffffb215SMTPIN_ADDED@mx.gmail.com>
  • Reply-to: Midsummer Sun <midsummer.sun@gmail.com>

First of all I am happy to report that I have solved the problem by
pre-editing the XML string. My application now works fine.

I simply used substring function as below to strip the DTD reference

rsp = rsp.substring(rsp.indexOf("<MESSAGING>"));

But I am *eager* to learn the EntityResolver approach. 
I have not done anything special. I have just extended my class with
SAX class DefaultHandler.
I then set my class object as the EntityResolver handler for the
DocumentBuilder as -
builder.setEntityResolver(obj);

JDK 1.4.2 document says -
"
EntityResolver is a default base class for SAX2 event handlers. 
This class is available as a convenience base class for SAX2
applications: it provides default implementations for all of the
callbacks in the four core SAX2 handler classes:
1) EntityResolver 
2) DTDHandler 
3) ContentHandler 
3) ErrorHandler 
"
So I think simply this should have worked; but it is not working..

As another solution for EntityResolver approach(without doing anything
as above), I called setEntityResolver method(with argument null) on
the DocumentBuilder object. The JDK document says about this..
"
Specify the EntityResolver to be used to resolve entities present in
the XML document to be parsed. Setting this to null will result in the
underlying implementation using it's own default implementation and
behavior.
"
But this also does'nt work.

What do I need to do to set the EntityResolver correctly?

Best regards,


On Thu, 31 Mar 2005 11:43:06 +0100, Michael Kay <mike@saxonica.com> wrote:
> What does your EntityResolver actually do?
> 
> Michael Kay
> http://www.saxonica.com/
> 
> > -----Original Message-----
> > From: Midsummer Sun [mailto:midsummer.sun@gmail.com]
> > Sent: 31 March 2005 11:25
> > To: xml-dev@lists.xml.org
> > Subject: Re: [xml-dev] 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,




 

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

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