Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locate SYSTEM entities when SAX parsing an XML document

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use javax.xml.parsers.SAXParser to parse an XML document. It is OK until the XML document tries to use SYSTEM entities to reference another XML document. You know the idea: -


Here's the existing parsing code: -


I need to tell the SAXParser how to find file "foo.xml". It is not an ordinary file, or an HTTP resource, but I could easily provide a method to locate it, via the relative path. I could return a Reader or an InputStream. The problem is I don't know what hook would allow me to do so.

Any suggestions?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that the idea behind the EntityResolver interface?
Presumably you could implement the resolveEntity method in your custom class and create an InputSource pointing to the file.
See org.xml.sax.EntityResolver in the Javadocs

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic