commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Agustin Barto" <aba...@gmail.com>
Subject Simple Digester ruleset for a list of String
Date Sun, 03 Sep 2006 15:43:30 GMT
I need to parse an XML like this:

<message-list>
  <message>Message1</message>
  <message>Message2</message>
  ...
  <message>MessageN</message>
</messge-list>

which should render a List<String> (or at least Collection<String>).
Right now what I do is this:

	@SuppressWarnings("unchecked")
	protected static List<String> parseMessageList(String uri) throws
IOException, SAXException {
		Digester digester = new Digester();
		
		digester.setValidating(false);
		digester.addObjectCreate("message-list", ArrayList.class );
		digester.addCallMethod("message-list/message", "add", 1, new Class[]
{ String.class });
		digester.addCallParam("message-list/message", 0);
		
		return (List<String>) digester.parse(uri);
	}

...and I was wondering if it's the right way to do it, and if not, if
there is a better way.

Agustin

---------------------------------------------------------------------
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