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

RE: Problem parsing XML file with Xerces-J


entityresolver xerces
You need to do two things

(a) register your EntityResolver with the parser - you've done this

(b) use your EntityResolver to resolve URI references - you seem to have
omitted this step.

This means you need to implement the resolveEntity() method to do something
useful when presented with the system ID of the external DTD - like
returning an InputSource pointing to an empty DTD.

The default implementation of resolveEntity() in DefaultHandler does
nothing, you need to override it.

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


> -----Original Message-----
> From: Midsummer Sun [mailto:midsummer.sun@g...] 
> Sent: 31 March 2005 12:07
> To: Michael Kay
> Cc: xml-dev@l...
> Subject: Re:  Problem parsing XML file with Xerces-J
> 
> 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.