Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Further thoughts on filters and factories

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Xom Interest <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] Further thoughts on filters and factories
  • Date: Mon, 7 Jul 2003 09:51:33 -0400

At 9:38 AM -0400 6/18/03, John Cowan wrote:

This is a classic datahead/dochead split, and the fact that you're
ambivalent shows that you have some of each in your makeup. :-)
Dataheads think of an element as a container for its content, and
if the container is removed, the content goes to Tumbolia with it.
Docheads think of elements as basically annotations of ranges, and if
the annotation is removed, the underlying content remains.

I don't think you can make everyone happy here. Just make sure that
*some* path through the code makes it possible to do either operation.


I've been playing with the API, and I think something John suggested here is likely to work. First I'll rename makeElement to beginMakeElement and endElement to finishMakeElement. (Would beginMakingElement and finishMakingElement be more grammatical? or perhaps startMakingElement and finishMakingElement?)

Next, I'll move the actual attachment to the tree in XOMHandler into endElement instead of startElement. The element node will only be attached to the tree if finishMakeElement returns non-null. Thus returning null from beginMakeElement will remove the start-tag and end-tag, while leaving the contents intact. Returning null from finishMakeElement will remove the entire element including its contents. This is a more consistent API with no need to call detach.

The only downside I see to this approach is that it will no longer be possible to walk up the tree from the currently built element. For instance, it won't be possible to access the Document object that contains a node until after the entire document has been parsed. Looking at my samples, I don't think this is a major issue. Most use cases that require walking up the tree, normally have pretty random access that requires the entire tree to be in memory before beginning processing anyway. XSLT/XPath is the classic example. And if you really wanted to know what the ancestors were, you could always put a stack in the factory. Can anyone think of any problem that this new approach would make significantly more difficult to solve compared to the old approach?
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page