commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject Re: Attribute question for Commons Digester
Date Fri, 29 Jun 2007 10:58:51 GMT
Yeah, I didn't notice the "_" (or read the rest of the request).  You'll
need a custom rule here to convert that value, otherwise SetProperties would
work (and you don't need to specify "id"/"id" because it'll match the
properties to the attributes if they match exactly).  Why the underscore
anyway?

On 6/29/07, Poulton, Jonathan <jpoulton@verisign.com> wrote:
>
> You mean:
>
>         digester.addObjectCreate("article", Article.class);
>         digester.addSetProperties("article", "id", "id");
>
> Yup. I've tried that. The actual value of the id field in the XML
> "_1234" is ignored and "0" is set on the Article id field instead. I
> assume that this is because of the underscore in the id field.
>
> -----Original Message-----
> From: jcarman@carmanconsulting.com [mailto:jcarman@carmanconsulting.com]
> On Behalf Of James Carman
> Sent: 29 June 2007 11:48
> To: Jakarta Commons Users List
> Subject: Re: Attribute question for Commons Digester
>
> Have you tried an ObjectCreate followed by a SetProperties?
>
> On 6/29/07, Poulton, Jonathan <jpoulton@verisign.com> wrote:
> >
> > Surely someone has done this before?
> >
> >
> > -----Original Message-----
> > From: Poulton, Jonathan [mailto:jpoulton@verisign.com]
> > Sent: 28 June 2007 17:41
> > To: commons-user@jakarta.apache.org
> > Subject: Digester problem
> >
> > Hi there,
> > I've tried finding a solution to what I think should be quite a simple
>
> > problem using the Commons Digester, but the tutorials I can find on
> > the subject only really cover the basics and aren't of any help.
> >
> > Given an XML fragment like the following:
> >
> > <article id="_1234">
> >     <text>...</text>
> > </article>
> >
> > I need the Digester to call a method on an Article class, with the
> > following signiture:
> >
> > public void setId(long id);
> >
> > In other words I just need a Rule that will fire for an XML "id"
> > attribute, and remove an underscore from the front of a String before
> > converting it to a long, and calling the appropriate method.
> >
> > I realise that this will require some kind of custom class to chop up
> > the String, but the pattern you apply to matching the rule
> > ("article/id") appears to refer to a nested id element, rather than an
>
> > id attribute.
> >
> > I can't seem to find an example of this anywhere. All the custom rules
>
> > examples appear to refer to nested elements. Any suggestions? Have I
> > missed something in the API?
> >
> > Cheers
> >
> > Jon
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message