[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|