[
Lists Home |
Date Index |
Thread Index
]
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@gmail.com]
> Sent: 31 March 2005 12:07
> To: Michael Kay
> Cc: xml-dev@lists.xml.org
> Subject: Re: [xml-dev] 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@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,
>
|