You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Valerio Schiavoni <va...@gmail.com> on 2006/01/25 15:19:19 UTC

[digester] delegate the parsing of some nodes to different parsers

Hello,
suppose you have something like:
<root>
  <foo>
     <bar>
     .....
     </bar>
  </foo>
</root>

I already have the digester code to istantiate a Bar object, if given as
parameter to BarParser.read(String s) i pass as
actual parameter everything between <bar> and </bar>.

Now i want to have a RootParser, so that if i pass it everything between
root tags, whenever it encounter any bar tags,
it delegates the parsing of that portion of the xml document to BarParser.

Is it possible ?

thanks,
valerio
--
To Iterate is Human, to Recurse, Divine
James O. Coplien, Bell Labs
(how good is to be human indeed)

Re: [digester] delegate the parsing of some nodes to different parsers

Posted by Simon Kitching <sk...@apache.org>.
On Wed, 2006-01-25 at 15:19 +0100, Valerio Schiavoni wrote:
> Hello,
> suppose you have something like:
> <root>
>   <foo>
>      <bar>
>      .....
>      </bar>
>   </foo>
> </root>
> 
> I already have the digester code to istantiate a Bar object, if given as
> parameter to BarParser.read(String s) i pass as
> actual parameter everything between <bar> and </bar>.
> 
> Now i want to have a RootParser, so that if i pass it everything between
> root tags, whenever it encounter any bar tags,
> it delegates the parsing of that portion of the xml document to BarParser.
> 
> Is it possible ?

I guess it's possible though I don't know of anyone that has tried this
before. 

You effectively need to get a reference to the xml parser that is
feeding events to the RootParser, and instead tell it to feed events to
the BarParser. In addition, I presume you'd need to grab the top object
off the RootParser's object stack and push it onto the BarParser's stack
so that the two "trees" of objects can be connected. At the end of the
bar element, you need to perform the reverse process. This sounds like
it is doable using a custom Rule class.

I don't know quite what you are trying to achieve with this. If the
intention is to be able to apply independent sets of rules for different
parts of the tree you might like to look at the "plugins" module of
Digester which implements that sort of functionality. Hopefully the
package javadoc describes its purpose adequately:
http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/api/org/apache/commons/digester/plugins/package-summary.html

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org