You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Евгений Антаев <an...@gmail.com> on 2009/02/04 19:43:48 UTC

Digester pattern with attribute

Hi

Can I use attribute value as a constraint in a pattern for Digester?

For example

<addressBook>
    ...
    <contact>
        <phone type='home'>00000000</phone>
        <phone type='work'>99999999</phone>
    </contact>
    ...
</addressBook>

I would like to use pattern to match home phone only. Something like
"contact/phone[@type='home']".

------
Evgeny

Thanks

Re: Digester pattern with attribute

Posted by Евгений Антаев <an...@gmail.com>.
That's right. Thank you, Rahul

------
Evgeny

On Wed, Feb 4, 2009 at 10:35 PM, Rahul Akolkar <ra...@gmail.com>wrote:

> On Wed, Feb 4, 2009 at 1:43 PM, Евгений Антаев <an...@gmail.com> wrote:
> > Hi
> >
> > Can I use attribute value as a constraint in a pattern for Digester?
> >
> > For example
> >
> > <addressBook>
> >    ...
> >    <contact>
> >        <phone type='home'>00000000</phone>
> >        <phone type='work'>99999999</phone>
> >    </contact>
> >    ...
> > </addressBook>
> >
> > I would like to use pattern to match home phone only. Something like
> > "contact/phone[@type='home']".
> >
> <snip/>
>
> No. Commons Digester uses what it calls element matching patterns --
> they aren't true XPath expressions so the example above can't be used
> as intended (only element names are matched).
>
> Short of defining your own digester Rule or Rules implementations,
> perhaps you can simply ignore the bits you don't care about (so lets
> say you use SetNextRule to add Phone objects to a Contact object, you
> could ignore phones that aren't home phones).
>
> -Rahul
>
>
> > ------
> > Evgeny
> >
> > Thanks
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: Digester pattern with attribute

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Feb 4, 2009 at 1:43 PM, Евгений Антаев <an...@gmail.com> wrote:
> Hi
>
> Can I use attribute value as a constraint in a pattern for Digester?
>
> For example
>
> <addressBook>
>    ...
>    <contact>
>        <phone type='home'>00000000</phone>
>        <phone type='work'>99999999</phone>
>    </contact>
>    ...
> </addressBook>
>
> I would like to use pattern to match home phone only. Something like
> "contact/phone[@type='home']".
>
<snip/>

No. Commons Digester uses what it calls element matching patterns --
they aren't true XPath expressions so the example above can't be used
as intended (only element names are matched).

Short of defining your own digester Rule or Rules implementations,
perhaps you can simply ignore the bits you don't care about (so lets
say you use SetNextRule to add Phone objects to a Contact object, you
could ignore phones that aren't home phones).

-Rahul


> ------
> Evgeny
>
> Thanks
>

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