You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stefan Burkard <ne...@burknet.ch> on 2005/02/16 15:57:29 UTC
[digester] concatenate multiple elements to a property
hi there
i'd like to concatenate multiple strings from several xml-elements (for
example all "stringelement"-values from the example-xml below) to one
string and add this string to an objectproperty. is this possible with
digester? has anybody a tip or a code example for me?
thanks and greetings
stefan
<elementlist>
<element>
<string-element></string-element>>
<other elements></other elements>
</element>
<element>
...as above
</element>
</elementlist>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [digester] concatenate multiple elements to a property
Posted by Luke Shannon <ls...@futurebrand.com>.
I'm a Digester newbie, but I will take a crack at this because it looks like
something I recently did.
Here is a digester method that would put all of the string-elements into a
StringBuffer and return that StringBuffer.
public static Vector digestDocument(File parseMe) throws IOException,
SAXException {
Digester digester = new Digester();
digester.setValidating(false);
//put a string buffer on the stack
digester.addObjectCreate("elementlist/element", StringBuffer.class);
//call the append method on the string-element pattern
digester.addCallMethod("elementlist/element/string-element", "append", 1);
//the contents of the tag as the parameter to append
digester.addCallParam("elementlist/element/string-element", 0);
return (StringBuffer)digester.parse(parseMe);
}
You could do something like this to set your object property.
myObject.setObjectProperty(digestDocument(file).toString());
Hopefully this makes sense.
Luke
----- Original Message -----
From: "Stefan Burkard" <ne...@burknet.ch>
To: <co...@jakarta.apache.org>
Sent: Wednesday, February 16, 2005 9:57 AM
Subject: [digester] concatenate multiple elements to a property
> hi there
>
> i'd like to concatenate multiple strings from several xml-elements (for
> example all "stringelement"-values from the example-xml below) to one
> string and add this string to an objectproperty. is this possible with
> digester? has anybody a tip or a code example for me?
>
> thanks and greetings
> stefan
>
> <elementlist>
> <element>
> <string-element></string-element>>
> <other elements></other elements>
> </element>
> <element>
> ...as above
> </element>
> </elementlist>
>
>
> ---------------------------------------------------------------------
> 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