You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Arved Sandstrom <Ar...@chebucto.ns.ca> on 1999/12/11 04:53:49 UTC

Locator interface in SAX Parsers [ OFFTOPIC ]

I thought this would be about as good a place as any to ask this question.
There isn't a comp.text.xml.programming.java.saxparsers newsgroup that I'm
aware of. :-)

I've been working on a web resource for MacOS XML processing, and as part
of that I set up a little SAX application that ought to be able to use any
SAX parser. Here's the rub - it uses Locator info. SAX doesn't require a
parser to implement Locator, it just strongly encourages it, and XP, for
example, does.

xml4j (I've been using the 2.0.15 version) does _not_. I have to assume
that maybe, in that case, neither does Xerces-J. A Locator _is_ used, but
it's internal, and can beobtained by calling a getLocator() method.

So, the problem is, I want to write a generic app that only imports
org.xml.sax and standard Java. No reference to XP or xml4j or whatever. If
all the parsers implemented Locator I could just cast the parser instance
to Locator, and pass that to setDocumentLocator on the DocumentHandler.
But because of xml4j this is a no-go.

So I looked at reflection. Get the Class object for the parser, get the
name, and if that equals "com.ibm.xml.parsers.SAXParser", for example,
then I use getMethod() on the class, and use invoke() on the method. No
need to hardwire anything that would require imports of specific parser
classes.

Next problem: getLocator() is a protected method. getMethod() only
reflects public methods. So at this point I'm thinking that I can not
actually write a generic SAX application that uses Locator, and that can
handle both XP and xml4j, and _not_ import xml4j.jar at compile time.

Any thoughts on this? Am I missing something here? It also occurred to me
that this is one instance of switching between XP and xml4j (by extension,
Xerces-J) not being so routine. Maybe there are more. Since we are
transitioning FOP over to Xerces-J, _but_ retaining the ability to specify
XP, maybe this won't be as trouble-free as we expect. Just a thought.

Regards, Arved Sandstrom