commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simon <>
Subject Re: Apache Digester SetNestedPropertiesRule
Date Fri, 10 Aug 2007 15:19:20 GMT
On Fri, 2007-08-10 at 07:04 -0700, DM wrote:
> Hi,
> I'm writing my own subclass of SetNestedPropertiesRule. Within the body of the overriden
begin method
> begin(java.lang.String namespace, java.lang.String name, org.xml.sax.Attributes attributes)
>     // my implementation here
> }
> I'd like to access the text of the nested elements. So, if the rule fires for the <subscriber>
element shown below:
> <subscriber>
>   <nn>sub-nick3</nn>
>   <pn>2000000003</pn>
> </subscriber>
> Then I need to be able to read "sub-nick3" and "200000003" within the begin() method.
Any idea how I can do this?

You can't. Not in the begin method.

Digester uses SAX, ie event-driven xml parsing. In other words, the xml
input goes into a standard xml parser that then emits SAX parsing events
that digester catches and handles.

SAX is very efficient, but there is no way to "look ahead" in the file.
In particular when a "start element" event is sent by the parser the xml
attributes are available, but the nested elements have not yet been read
from the input so cannot be accessed.

That's why the SetNestedPropertiesRule class is complex...



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

View raw message