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

Re: Problem parsing XML file with Xerces-J

  • To: Michael Kay <mike@s...>
  • Subject: Re: Problem parsing XML file with Xerces-J
  • From: Midsummer Sun <midsummer.sun@g...>
  • Date: Thu, 31 Mar 2005 16:37:25 +0530
  • Cc: xml-dev@l...
  • 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@m...>
  • References: <bb5e8b8605033102246096e3ed@m...> <424bd441.1e7d4a1f.35e0.ffffb215SMTPIN_ADDED@m...>
  • Reply-to: Midsummer Sun <midsummer.sun@g...>

xerces entityresolver
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@s...> wrote:
> 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,

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.