Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Builder as ContentHandler

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Michael Kay <mike AT saxonica.com>
  • Cc: 'XOM' <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Builder as ContentHandler
  • Date: Sat, 29 Mar 2008 06:51:12 -0700

Michael Kay wrote:
Is there any way of building a XOM document from a stream of SAX events?
That is, something that implements ContentHandler, is called to receive the
SAX events, and returns the document node?


Not really. What you're doing currently in XOMWriter is probably the best option.

I've tried very hard to make XOM a self-contained API; that is, one that does not expose a lot of dependencies on other APIs. The goal is to be able to do complete XML parsing without having to first learn SAX, DOM, JAXP, or any other such thing. With the exception of a few references to XMLReader in the builder class, I think I've mostly succeeded in the core. This also allows me to avoid making a lot of checks I'd have to make in XOMHandler if anyone could call its methods with any data at any time, and is an important optimization.

I could potentially add one more method to SAXConverter in 1.3. It would have a method signature like this:


public Document convert(ContentHandler handler)
throws XMLException

That sig wouldn't quite work though. You're probably right that we need something with a callback; maybe even a separate class. What do you think the minimal signature for that would look like? Maybe

public class SAXConverter {

public SAXConverter(ContentHandler handler) {
this,handler = handler;
}

// Should this throw an exception if there's
// an unclosed element in the stream?
public Nodes getResult() {
...
}

}


--
Elliotte Rusty Harold elharo AT metalab.unc.edu
Java I/O 2nd Edition Just Published!
http://www.cafeaulait.org/books/javaio2/
http://www.amazon.com/exec/obidos/ISBN=0596527500/ref=nosim/cafeaulaitA/




Archive powered by MHonArc 2.6.24.

Top of Page