OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] setEntityResolver() not setting entity resolver

[ Lists Home | Date Index | Thread Index ]

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








 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS