commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: Digester - help getting the <!-- comments --> from a tag
Date Sun, 02 Jul 2006 22:12:31 GMT
On Fri, 2006-06-30 at 12:41 -0400, Konstantin G wrote:
> Hello All,
> I am using Digester for an xml parsing project ( quite successfully)
> and I need some help figuring out how to save the contents of a
> comment within a given tag, such as:
>         <prompt>
>           <!-- <audio expr="file.wav'"/> -->
>         </prompt>
> I am specifically looking for occurrences of the commented out tag
> audio, and if there is a way to parse comments for xml tags, that
> would be great.  Minimally, I would like to save the comments ( or the
> entirety of the text between the start and end of the tag) to a
> string.  Since Digester uses SAX parsing, which might ignore comments,
> I am not sure if this is possible in the scope of Digester.

No, handling comments is not possible in Digester as far as I know
(AFAIK). In order to be informed of comments by the sax parser, Digester
would need to implement the org.xml.sax.ext.LexicalHandler interface,
and it does not. The "normal" org.xml.sax.ContentHandler interface which
Digester uses doesn't get notified of comments.

You might be able to do something like create your own XMLParser
instance and point it at your own filter class which implements
ContentHandler and LexicalHandler. Your filter could then delegate
ContentHandler methods through to a Digester instance. When the filter
is notified of a comment it could access the digester stack to do stuff.
However it doesn't sound terribly easy to me...



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message