Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] How to get access to XOM ContentHandlers?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Thomas Hicks <hickst AT theriver.com>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] How to get access to XOM ContentHandlers?
  • Date: Fri, 24 Aug 2007 10:29:01 -0700

No reply to my post....but I suppose it's my fault: I didn't
phase it as an interrogative. I really meant to ask some questions:

1) Is my analysis of the situation incorrect or incomplete?
2) Is there some other way to do this? (a workaround)?
3) What's the motive for hiding access to XOM's content handlers?
4) Might this be changed anytime in the future?

Thanks for any and all consideration of the problem.
-tom


At 03:05 PM 8/8/2007, I wrote:
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







Archive powered by MHonArc 2.6.24.

Top of Page