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

Re: setEntityResolver() not setting entity resolver


setentityresolver
On Thu, 6 Nov 2003, Jirka Kosek wrote:

> >   SAXParserFactory factory = SAXParserFactory.newInstance();
> >   SAXParser parser = factory.newSAXParser();
> >   XMLReader xmlReader = parser.getXMLReader();
> >   MyEntityResolver er = new MyEntityResolver();
> >   xmlReader.setEntityResolver(er);
> >   parser.parse (new InputSource (...), handler);
> 
> And you want to ... be handled through your entity resolver? In that 
> case you must resolve entity manually as JAXP doesn't use EntityResolver 
> for parse method:
> 
> parser.parse(er.resolveEntity("", "..."), handler);

No, I want the DTD reference in the document to be handled by the
entity resolver.

> Your entity resolver should be used for resolving all entites in your 
> files (like external DTD, external text entities, ...) automatically. If 
> not, something is wrong with either your entity resolver or your parser.

Hmm. Or maybe I'm doing something else wrong. So you believe that if I set
the entity resolver as above, then the DTD reference in the document
should be resolved by the entity resolver? It doesn't appear to be
happening. I tested with an entity resolver like so:

public class MyEntityResolver implements EntityResolver {
  public InputSource resolveEntity (String publicId, String systemId)
  {
      System.out.println("RESOLVING ENTITY");
      return null;
  }
}

"RESOLVING ENTITY" is never printed to standard out, even though there is 
a DTD reference in the document. Instead, I get an error message from the 
parser that the DTD could not be found (it's looking in the current 
directory for the DTD's system ID). I concluded that my custom resolver 
wasn't getting used at all.

I'm using the parser which ships with JDK 1.4.1_01; I would be surprised 
if that were buggy, but maybe that's the problem. I'd expect the problem 
to be with my code.

Just for kicks, I added a reference to an external entity into the 
document, to see if that got resolved through the resolver. No. (Well, 
"no" meaning "my resolver class didn't print its message.")

j





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.