xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
[XOM-interest] How to get access to XOM ContentHandlers?
- From: Thomas Hicks <hickst AT theriver.com>
- To: xom-interest AT lists.ibiblio.org
- Subject: [XOM-interest] How to get access to XOM ContentHandlers?
- Date: Wed, 08 Aug 2007 15:05:28 -0700
How to get access to an XOM ContentHandler?
I'm connecting XOM to an existing 3rd party library
which allows multiple different XML representations
to be interconverted. These representations all implement
an interface with one conversion method: 'handleContent'
which looks roughly like this (this is the JDOM representation):
/** JDOM implementation of the interface */
public class JDOMSAXAspect implements IAspectSAX {
...
private Document jdomDocument;
...
public void handleContent(XMLReader rdr) {
SAXOutputter saxo = new SAXOutputter(rdr.getContentHandler());
saxo.output(jdomDocument);
}
}
As you can see, they extract the SAX ContentHandler from the
given XMLReader and allow it to handle the events generated
by parsing the encapsulated document.
The question is how to build an XMLReader containing an
XOM ContentHandler (like nu.xom.NonVerifyingHandler) to
pass into one of these representation (for conversion of
the document to XOM).
XOMHandler and NonVerifyingHandler have only XOM package visibility.
I can't use the SAXConverter class because its only constructor
requires a ContentHandler. (It would be very convenient if there
was a no-args constructor which defaulted to one of the XOMHandlers).
Note that in JDOM I can accomplish the conversion from
representation XXX to JDOM with the following code because
JDOM allows the instantiation of its content handler:
IAspectSAX ias = <get instance of representation XXX implementing IAspectSAX>...
org.jdom.input.SAXHandler sh = new SAXHandler();
XMLReader xrdr = XMLReaderFactory.createXMLReader();
xrdr.setContentHandler(sh);
xrdr.setProperty("http://xml.org/sax/properties/lexical-handler", sh);
ias.handleContent(xrdr);
org.jdom.Document = sh.getDocument();
But I can't seem to find a way to do this in XOM, because of the
visibility of the XOM ContentHandlers.
Any thoughts appreciated,
-tom
-
[XOM-interest] How to get access to XOM ContentHandlers?,
Thomas Hicks, 08/08/2007
-
Re: [XOM-interest] How to get access to XOM ContentHandlers?,
Thomas Hicks, 08/24/2007
-
Re: [XOM-interest] How to get access to XOM ContentHandlers?,
Elliotte Harold, 08/25/2007
- Re: [XOM-interest] How to get access to XOM ContentHandlers?, Thomas Hicks, 08/29/2007
-
Re: [XOM-interest] How to get access to XOM ContentHandlers?,
Elliotte Harold, 08/25/2007
-
Re: [XOM-interest] How to get access to XOM ContentHandlers?,
Thomas Hicks, 08/24/2007
Archive powered by MHonArc 2.6.24.