xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Using XOM as a stream processor
- From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
- To: XOM-interest AT lists.ibiblio.org
- Cc:
- Subject: Re: [XOM-interest] Using XOM as a stream processor
- Date: Mon, 2 Feb 2004 13:27:04 -0500
At 5:49 PM +0000 2/2/04, George Richard Russell wrote:
I'd like to know how to process XML in a streaming manner using XOM. The
tutorial doesn't mention this (yet, I know) and I can't quite get it
from the examples / javadoc alone.
Yes, most of the tutorial is scheduled to be writyten during beta. Quick version:
Subclass NodeFactory and override the methods you wish to process in a streaming fashion. Pass an instance of your NodeFactory subclass to the Builder constructor. The most common method to override is finishMakingElement(). You can operate on the element passed to that method then return an empty Nodes object to keep it from being added to the tree. Or if you do want to add it to the tree just call super.finishMakingElement(element). There are several examples of this in the nu.xom.samples package. Look for those that begin StreamingFoo
What I'd like to do is process, for example, the item elements and their
contents from an RSS feed. I'd like to be handed, one at a time, an
Element with its content, and possibly control the construction of the
Element to constrain what children are added. So, I'm interested in i.e.
item's, and the title, link, description child elements with their text
content. Could I restrict the construction to just these, and how would
I do so?
Well, I haven't compiled it, but something like this:
private Nodes empty = new Nodes();
public void finishMakingElement(Element element) {
String name = element.getLocalName();
if ("title".equals(name)
|| "link".equals(name)
|| "description".equals(name)
|| "rss".equals(name)
|| "item".equals(name) {
return super.finishMakingElement(element);
}
return empty;
}
It can be customized further. Look for the samples with the word "Filter" in their class names to see how to do this.
A _tiny_ buglet ; a typo in the NodeFactory java doc in the spelling of
instruction.
OK. Exactly where?
--
Elliotte Rusty Harold
elharo AT metalab.unc.edu
Effective XML (Addison-Wesley, 2003)
http://www.cafeconleche.org/books/effectivexml
http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA
-
[XOM-interest] Using XOM as a stream processor,
George Richard Russell, 02/02/2004
- Re: [XOM-interest] Using XOM as a stream processor, Elliotte Rusty Harold, 02/02/2004
Archive powered by MHonArc 2.6.24.