You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Gao Di <ja...@yahoo.com.cn> on 2004/08/26 05:26:25 UTC

[Digester]some problem when parsing xml

i have defined 2 javabeans,device.java and
subdevice.java,and i have the folllowing xml file:
1.
<OBJ>
  <device name="n1"/>
</OBJ>
......

2.
<OBJ>
  <device name="n1">
    <subdevice name="m1"/>
  </device>
</OBJ>
......

on the first format,i want to parse the xml content to
device.java,while on the second format,i want to fill
the xml content to subdevice.java,but the question is
i don't know which format i will meet,it appears
randomly,what should i do to distinguish them?


_________________________________________________________
Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
http://music.yisou.com/
美女明星应有尽有,搜遍美图、艳图和酷图
http://image.yisou.com
1G就是1000兆,雅虎电邮自助扩容!
http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/

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


Re: [Digester]some problem when parsing xml

Posted by Gao Di <ja...@yahoo.com.cn>.
thank for your help,it works.
 --- Simon Kitching <si...@ecnetwork.co.nz> 的正文:
> 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
> 
>  

_________________________________________________________
Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
http://music.yisou.com/
美女明星应有尽有,搜遍美图、艳图和酷图
http://image.yisou.com
1G就是1000兆,雅虎电邮自助扩容!
http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/

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


Re: [Digester]some problem when parsing xml

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
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


Re: [Digester]some problem when parsing xml

Posted by José Antonio Pérez Testa <ja...@indra.es>.
I think you have the same problem that in :

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg07607.html

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.
>
> --- Jos�� Antonio P��rez Testa <ja...@indra.es>
>�����ģ�
>  
>
>>Can you explain it a little bit?. I can't see the
>>problem.
>>
>>Gao Di wrote:
>>
>>    
>>
>>>i have defined 2 javabeans,device.java and
>>>subdevice.java,and i have the folllowing xml file:
>>>1.
>>><OBJ>
>>> <device name="n1"/>
>>></OBJ>
>>>......
>>>
>>>2.
>>><OBJ>
>>> <device name="n1">
>>>   <subdevice name="m1"/>
>>> </device>
>>></OBJ>
>>>......
>>>
>>>on the first format,i want to parse the xml content
>>>      
>>>
>>to
>>    
>>
>>>device.java,while on the second format,i want to
>>>      
>>>
>>fill
>>    
>>
>>>the xml content to subdevice.java,but the question
>>>      
>>>
>>is
>>    
>>
>>>i don't know which format i will meet,it appears
>>>randomly,what should i do to distinguish them?
>>>
>>>
>>>      
>>>
>>_________________________________________________________
>>    
>>
>>>Do You Yahoo!?
>>>150����MP3����ѣ������������ֵ���
>>>http://music.yisou.com/
>>>��Ů����Ӧ�о��У��ѱ���ͼ����ͼ�Ϳ�ͼ
>>>http://image.yisou.com
>>>1G����1000�ף��Ż������������ݣ�
>>>      
>>>
>>http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
>>    
>>
>>---------------------------------------------------------------------
>>    
>>
>>>To unsubscribe, e-mail:
>>>      
>>>
>>commons-user-unsubscribe@jakarta.apache.org
>>    
>>
>>>For additional commands, e-mail:
>>>      
>>>
>>commons-user-help@jakarta.apache.org
>>    
>>
>>> 
>>>
>>>      
>>>
>-------------------------------------------------------------------------------------------------------------------
>  
>
>>Este correo electr�nico y, en su caso, cualquier
>>fichero anexo al mismo, contiene informaci�n de
>>car�cter confidencial exclusivamente dirigida a su
>>destinatario o destinatarios. Queda prohibida su
>>divulgaci�n, copia o distribuci�n a terceros sin la
>>previa autorizaci�n escrita de Indra. En el caso de
>>haber recibido este correo electr�nico por error, se
>>ruega notificar inmediatamente esta circunstancia
>>mediante reenv�o a la direcci�n electr�nica del
>>remitente.
>>
>>The information in this e-mail and in any
>>attachments is confidential and solely for the
>>attention and use of the named addressee(s). You are
>>hereby notified that any dissemination, distribution
>>or copy of this communication is prohibited without
>>the prior written consent of Indra. If you have
>>received this communication in error, please, notify
>>the sender by reply e-mail
>>
>>
>>    
>>
>---------------------------------------------------------------------
>  
>
>>To unsubscribe, e-mail:
>>commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail:
>>commons-user-help@jakarta.apache.org
>>
>> 
>>    
>>
>
>_________________________________________________________
>Do You Yahoo!?
>150����MP3����ѣ������������ֵ���
>http://music.yisou.com/
>��Ů����Ӧ�о��У��ѱ���ͼ����ͼ�Ϳ�ͼ
>http://image.yisou.com
>1G����1000�ף��Ż������������ݣ�
>http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>
-------------------------------------------------------------------------------------------------------------------
Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante reenv�o a la direcci�n electr�nica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail

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


Re: [Digester]some problem when parsing xml

Posted by Gao Di <ja...@yahoo.com.cn>.
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.

 --- Jos�� Antonio P��rez Testa <ja...@indra.es>
�����ģ�
> Can you explain it a little bit?. I can't see the
> problem.
> 
> Gao Di wrote:
> 
> >i have defined 2 javabeans,device.java and
> >subdevice.java,and i have the folllowing xml file:
> >1.
> ><OBJ>
> >  <device name="n1"/>
> ></OBJ>
> >......
> >
> >2.
> ><OBJ>
> >  <device name="n1">
> >    <subdevice name="m1"/>
> >  </device>
> ></OBJ>
> >......
> >
> >on the first format,i want to parse the xml content
> to
> >device.java,while on the second format,i want to
> fill
> >the xml content to subdevice.java,but the question
> is
> >i don't know which format i will meet,it appears
> >randomly,what should i do to distinguish them?
> >
> >
>
>_________________________________________________________
> >Do You Yahoo!?
> >150����MP3����ѣ������������ֵ���
> >http://music.yisou.com/
> >��Ů����Ӧ�о��У��ѱ���ͼ����ͼ�Ϳ�ͼ
> >http://image.yisou.com
> >1G����1000�ף��Ż������������ݣ�
>
>http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> >
> >  
> >
>
-------------------------------------------------------------------------------------------------------------------
> Este correo electr�nico y, en su caso, cualquier
> fichero anexo al mismo, contiene informaci�n de
> car�cter confidencial exclusivamente dirigida a su
> destinatario o destinatarios. Queda prohibida su
> divulgaci�n, copia o distribuci�n a terceros sin la
> previa autorizaci�n escrita de Indra. En el caso de
> haber recibido este correo electr�nico por error, se
> ruega notificar inmediatamente esta circunstancia
> mediante reenv�o a la direcci�n electr�nica del
> remitente.
> 
> The information in this e-mail and in any
> attachments is confidential and solely for the
> attention and use of the named addressee(s). You are
> hereby notified that any dissemination, distribution
> or copy of this communication is prohibited without
> the prior written consent of Indra. If you have
> received this communication in error, please, notify
> the sender by reply e-mail
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
>  

_________________________________________________________
Do You Yahoo!?
150����MP3����ѣ������������ֵ���
http://music.yisou.com/
��Ů����Ӧ�о��У��ѱ���ͼ����ͼ�Ϳ�ͼ
http://image.yisou.com
1G����1000�ף��Ż������������ݣ�
http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/

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


Re: [Digester]some problem when parsing xml

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Can you explain it a little bit?. I can't see the problem.

Gao Di wrote:

>i have defined 2 javabeans,device.java and
>subdevice.java,and i have the folllowing xml file:
>1.
><OBJ>
>  <device name="n1"/>
></OBJ>
>......
>
>2.
><OBJ>
>  <device name="n1">
>    <subdevice name="m1"/>
>  </device>
></OBJ>
>......
>
>on the first format,i want to parse the xml content to
>device.java,while on the second format,i want to fill
>the xml content to subdevice.java,but the question is
>i don't know which format i will meet,it appears
>randomly,what should i do to distinguish them?
>
>
>_________________________________________________________
>Do You Yahoo!?
>150����MP3����ѣ������������ֵ���
>http://music.yisou.com/
>��Ů����Ӧ�о��У��ѱ���ͼ����ͼ�Ϳ�ͼ
>http://image.yisou.com
>1G����1000�ף��Ż������������ݣ�
>http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>
-------------------------------------------------------------------------------------------------------------------
Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante reenv�o a la direcci�n electr�nica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail

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