[jdom-interest] Building a small portion of a document

Laurent Bihanic laurent.bihanic at atosorigin.com
Wed Mar 27 09:52:53 PST 2002


You might be interested with org.jdom.contrib.input.scanner.ElementScanner (in 
JDOM's contrib module) which is a SAX filter that let you register XPath 
expressions to match elements and notifies listeners when an element has been 
In your case:
    ElementScanner f = new ElementScanner();
    f.addElementListener(myListener, "b");  // Listens for all <b> elements

ElementListener defines a single method elementMatched(String path, Element e).

Although it was not intended for this purpose, you listener could throw a 
JDOMException to abort the parse. In the above example, it would result in 
f.parse() throwing a SAXException wrapping the JDOMException thrown by the 

If you don't want to process JDOM elements or if your element structure is 
simple, you can achieve the same result by implementing your own SAX 
ContentHandler and throw a specific subclass of SAXException.

Hope this helps,


travis at thinkvirtual.com wrote:
> I am wondering if you can build a document from a certain element in an xml stream and have it stop building at the end of that element...
> ex: 
> <a>
>  <b> // start build here at element b
>    <c>text</c>
>  </b> // end build here
> </a>
> So this would totally skip the A, but at the sametime wouldn't throw the improper format exception.  Now I realize this is a SAXException, so is there anyway to do that with SAX?
> Travis Reeder
> Chief Software Architect
> www.ThinkVirtual.com
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


                  wWw    Zzzzz
                 (- -)
Laurent Bihanic           | Tel: +33 (0)1  (Direct line)
Atos Origin               |      +33 (0)1
Intégration - e-Business  | Fax: +33 (0)1
Les Miroirs - Bat. C      |
18, avenue d'Alsace       |
F-92926 La Defense Cedex  | e-Mail: laurent.bihanic at atosorigin.com

"Microsoft isn't the answer. Microsoft is the question and the answer
  is no."

The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?

More information about the jdom-interest mailing list