commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Germuska <...@Germuska.com>
Subject Re: [Digester] Please help....
Date Wed, 18 Jun 2003 20:55:39 GMT
This is pretty hard to do with Digester's default rules because they 
don't really give you access to element names themselves -- just 
element and attribute content.  If you could put your XML through an 
XSLT transform before digesting to get something more like
<order>
   <entry key="account" value="12345" />
   <entry key="symbol" value="IBM" />
</order>

it would be a piece of cake.  It would be about as easy if you had 
the values inside elements
<order>
   <entry>
     <key>account</key>
     <value>12345</value>
...
</order>

For the first:
         digester.addObjectCreate("order", java.util.HashMap.class);
         digester.addCallMethod("order/entry","put", 2);
         digester.addCallParam("order/entry",0, "key");
         digester.addCallParam("order/entry",1, "value");

For the second:
         digester.addObjectCreate("order", java.util.HashMap.class);
         digester.addCallMethod("order/entry","put", 2);
         digester.addCallParam("order/entry/key",0);
         digester.addCallParam("order/entry/value", 1);

This assumes that you are treating the account number as a string, 
not an integer.  Using this approach,it would be hard to support 
different types for map entry values.

Do you have this flexibility?  Otherwise, you'll have to write your 
own subclass of org.apache.commons.digester.Rule, overriding the 
method:
  public void body(String namespace, String name, Attributes attributes).

I'm pretty sure there aren't any included Rule subclasses that do 
what you're thinking of.

I'm sure I should be using the XML rules syntax, but I still think in 
terms of the java method digester configuration...

Joe


At 16:11 -0400 6/18/03, Shvets, Steve wrote:
>Hi,
>
>I need to take following xml
><order>
>	<account>12345</account>
>	<symbol>IBM</symbol>
></order>
>
>and create a java.util.HashMap with
>
>key            value
>"account"    12345
>"symbol"     IBM
>
>How would the rules look like...Can someone provide a sample....
>
>Thank you, Steve
>
>
>Please do not transmit orders or instructions regarding a UBS account by
>email. The information provided in this email or any attachments is not an
>official transaction confirmation or account statement. For your protection,
>do not include account numbers, Social Security numbers, credit card
>numbers, passwords or other non-public information in your email. Because
>the information contained in this message may be privileged, confidential,
>proprietary or otherwise protected from disclosure, please notify us
>immediately by replying to this message and deleting it from your computer
>if you have received this communication in error.  Thank you.
>
>UBS Financial Services Inc.
>UBS International Inc.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org


-- 
--
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"If nature worked that way, the universe would crash all the time." 
	--Jaron Lanier

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


Mime
View raw message