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/18 10:28:16 UTC

[Digester]what's the difference when parsing xml files like these?

i have the xml file as below:
<devices>
<device>
  <name>Gw1</name>
</device>
<device>
  <name>Gw2</name>
</device>
</devices>
then i can use digester to parse it with this class
it's aim it to put the <device> to a javabean and then
put all <deivce> to a arraylist.
List devices = new ArrayList();

public void parsedevice(){ 
Digester digester = new Digester();
digester.push(this);
digester.addCallMethod("devices/device", "addDevice",
1);
digester.addCallParam("devices/device/name", 0);
digester.parse(test.xml); 	

public void addDevice(String name, ){
Device device = new Device(name);
devices.add(device);
}

but after some consideration,i changed the xml file
like this:
<devices>
<device name='Gw1'/>
<device name='Gw2'/>
</devices>
then,the parse code doesn't work any more,anyone can
help me how to parse this kind of xml file?

_________________________________________________________
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: [collections] LinkedMap and ListOrderedMap

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Both are provided to give you a choice of implementation.

IIRC, ListOrderedMap allows you to get a List object of keys, and also
allows you to choose your Map implementation (if you want something
unusual)..

To choose, the best answer is to performance test both in your application.
Bear in mind, the JDK implementation is like LinkedMap, so that might
suggest that is the better choice.

Stephen

----- Original Message -----
From: "Koji Sekiguchi" <ko...@bluemartini.com>
> These classes resemble each other, don't they?
> Are there any explanation/condition for choosing one of them
> whan I use ordered map in my application?



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


[collections] LinkedMap and ListOrderedMap

Posted by Koji Sekiguchi <ko...@bluemartini.com>.
These classes resemble each other, don't they?
Are there any explanation/condition for choosing one of them
whan I use ordered map in my application?

regards,

Koji



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


Re: [Digester]what's the difference when parsing xml files like these?

Posted by Gao Di <ja...@yahoo.com.cn>.
thx,i see,it's a good article.

 --- Jos�� Antonio P��rez Testa <ja...@indra.es>
�����ģ�
> Hi Gao, as always i recommed you my reference
> reading:
> http://www.onjava.com/lpt/a/2746
> you must use addSetProperties method. Following
> changes would work!
> 
> //digester.addCallMethod("devices/device",
> "addDevice",1);
> //digester.addCallParam("devices/device/name", 0);
> digester.|addSetProperties|("devices/device/name",
> "device");
> 
> 
> //public void addDevice(String name, ){
> public void setDevice(String name) {
>   Device device = new Device(name);
>   devices.add(device);
> }
> 
> ||
> 
> Saludos.
> 
> Gao Di wrote:
> 
> >i have the xml file as below:
> ><devices>
> ><device>
> >  <name>Gw1</name>
> ></device>
> ><device>
> >  <name>Gw2</name>
> ></device>
> ></devices>
> >then i can use digester to parse it with this class
> >it's aim it to put the <device> to a javabean and
> then
> >put all <deivce> to a arraylist.
> >List devices = new ArrayList();
> >
> >public void parsedevice(){ 
> >Digester digester = new Digester();
> >digester.push(this);
> >digester.addCallMethod("devices/device",
> "addDevice",
> >1);
> >digester.addCallParam("devices/device/name", 0);
> >digester.parse(test.xml); 	
> >
> >public void addDevice(String name, ){
> >Device device = new Device(name);
> >devices.add(device);
> >}
> >
> >but after some consideration,i changed the xml file
> >like this:
> ><devices>
> ><device name='Gw1'/>
> ><device name='Gw2'/>
> ></devices>
> >then,the parse code doesn't work any more,anyone
> can
> >help me how to parse this kind of xml file?
> >
>
>_________________________________________________________
> >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]what's the difference when parsing xml files like these?

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Hi Gao, as always i recommed you my reference reading:
http://www.onjava.com/lpt/a/2746
you must use addSetProperties method. Following changes would work!

//digester.addCallMethod("devices/device", "addDevice",1);
//digester.addCallParam("devices/device/name", 0);
digester.|addSetProperties|("devices/device/name", "device");


//public void addDevice(String name, ){
public void setDevice(String name) {
  Device device = new Device(name);
  devices.add(device);
}

||

Saludos.

Gao Di wrote:

>i have the xml file as below:
><devices>
><device>
>  <name>Gw1</name>
></device>
><device>
>  <name>Gw2</name>
></device>
></devices>
>then i can use digester to parse it with this class
>it's aim it to put the <device> to a javabean and then
>put all <deivce> to a arraylist.
>List devices = new ArrayList();
>
>public void parsedevice(){ 
>Digester digester = new Digester();
>digester.push(this);
>digester.addCallMethod("devices/device", "addDevice",
>1);
>digester.addCallParam("devices/device/name", 0);
>digester.parse(test.xml); 	
>
>public void addDevice(String name, ){
>Device device = new Device(name);
>devices.add(device);
>}
>
>but after some consideration,i changed the xml file
>like this:
><devices>
><device name='Gw1'/>
><device name='Gw2'/>
></devices>
>then,the parse code doesn't work any more,anyone can
>help me how to parse this kind of xml file?
>
>_________________________________________________________
>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