• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Proper use of an EntityResolver

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a number of XML documents, loaded from the database, that start with this:


And I am trying to apply an XSL transformation on the given document that I get as a String using this method:


And my CustomEntityResolver looks like this:


In my quest to use an EntityResolver, to avoid resolving the DTD over the network, I came across this method that org.dom4j.Document provides. Its documentation states:



The code as it stands right now throws a file not found exception every time the DTD isn't available on sourceforge, which happens more often than my users would like to see.


Can somebody please explain to me how I am using the EntityResolver incorrectly if I am?

Shouldn't providing my own implementation of an EntityResolver to the Document instance be sufficient to avoid having a transformer go on the network to resolve the DTD?

Thanks a bunch in advance for any and all help anybody can provide.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how dom4j works, but in JAXP you attach the EntityResolver to the parser which is going to parse the document. I'm surprised you can attach an EntityResolver in dom4j to a Document, I would have thought it was the output of a parser. But evidently it isn't.

Is your EntityResolver being called at all? Perhaps your string comparison isn't quite correct.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Paul Clapham, I think that your comparison might be wrong. Try printing the publicid and the systemid all the time to debug.
 
Mike Wallace
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your prompt reply, Paul, and Yves also.

I had initially put a big debug statement outside of the if in the EntityResolver, but as you suspected it isn't getting called at all, so it isn't an incorrect if statement since the code is never getting called.

I was under the impression that perhaps supplying the dom4j Document object itself with an EntityResolver somehow was detected by the Transformer, or the parser the Transormer is using behind the scenes I suppose, and was used to resolve the ID locally.

It makes sense from a theoretical standpoint, but it is surprising as Paul said. What didn't help much was there is not much documentation on what the setEntityResolver method is supposed to do. I wouldn't be shocked if it turns out that I'm just using it incorrectly, but I don't know what else to do. There isn't a way of giving a TransformerFactory or a Transformer your own EntityResolver.

I tried playing with a URIResolver and I supplied that to the TransfomerFactory but that also isn't getting called which makes me think that the underlying implementation, xalan, is simply ignoring resolvers all together.

Is there a better way of applying the transformation needed without depending on a specific implementation?
If not, which implementation do you suggest I use and how?

Thanks again guys.
 
Yves Zoundi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mike,

The EntityResolver has always worked for me with DOM4J(When using DOM4J with or without JAXP). What I always do is pass the EntityResolver in a SAXReader before creating the DOM4J document:

 
Mike Wallace
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for replying again, Yves.

I ended up giving up on trying to figure out what the point of dom4j's Document.setEntityResolver method and instead went with a similar approach to what you suggested.



Then I get a Transformer instance through TransformerHandler etc.

I now KNOW that my entity resolver is getting called and that it is functioning properly.

Thanks for all your time and assistance.
[ October 01, 2008: Message edited by: Mike Wallace ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic