commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: [Digester]some problem when parsing xml
Date Thu, 26 Aug 2004 22:23:24 GMT
On Fri, 2004-08-27 at 02:00, Gao Di wrote:
> sorry,i can make myself undersood,please see another
> problem:
> the xml file is looked like this:
> <?xml version="1.0" encoding="gb2312"?>
> <OBJ>		
> <PARAMS name="shanghai">
> <PARAM name="cpu" value="92%"/>
> <PARAM name="memory" value="256M"/>
> <PARAM name="status" value="active"/>
> <PARAM name="time" value="2004-07-15"/>
> </PARAMS>
> </OBJ>	
> and the javabean :Gateway
> public class Gateway implements java.io.Serializable {
> pivate String name;
> private String status;	
> private String cpu;
> private String memory;	
> private String time;		
> 	
> public String getName(){ return name; };
> public String getStatus(){ return status; };
> public String getCpu(){ return cpu; };
> public String getMemory(){ return memory; };	 
> public String getTime(){ return time; };	  	
> 	  
> public void setName(String name){ this.name = name; };
> public void setStatus(String status){ this.status =
> status; };
> public void setCpu(String cpu){ this.cpu = cpu; };
> public void setMemory(String memory){ this.memory =
> memory; };
> public void setTime(String time){ this.time = time; };
> public void setInfo(String name,String status,String
> cpu,String memory,String time){
> this.name = name;
> this.status = status;
> this.cpu = cpu;
> this.memory = memory;
> this.time = time;
> }
> }
> i want to put the
> (shanghai,92%,256M,active,2004-07-15) to the bean's
> five properties respectively,how to use digester parse
> it?
> cause the <PARAM> tag has the same attribute ,i don't
> know how to distinguish them.

Hi,

I think the following will do this (not tested):

digester.addObjectCreate("OBJ/PARAMS", Gateway.class);
digester.addSetProperties("OBJ/PARAMS");
digester.addSetProperty("OBJ/PARAMS/PARAM", "name", "value");

Regards,

Simon


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