commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luke Shannon" <lshan...@futurebrand.com>
Subject Re: [digester] concatenate multiple elements to a property
Date Wed, 16 Feb 2005 15:20:10 GMT
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" <newsgroup@burknet.ch>
To: <commons-user@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


Mime
View raw message