You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Aristos Stavrou <cs...@cs.ucy.ac.cy> on 2004/04/20 16:30:16 UTC

[Digester] Help please

Could you please help me on the following problem?


If I have an xml file containing the following element:
...
    <author name="....">
        <address> ... </address>
    </author>
....

and I have the following class defined for author element:

public class Author{
  private string name;
  private string address;

  public setName(name){
   name=this.name;
  }
  public getName(){
   return this.name;
  }
  public setAddress(addr){
   this.address=addr;
  }
  public getAddress(){
   return this.address;
  }

}

how do I say digester parser to set the "name" property of the stack top
object equal to the value of the "name" attribute of the author element.
I have tried:
addSetProperty(*/author, "name", "name");
but it doesn?t work. Is this the right rule?


Thanks in advance,
Aristos


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


Re: [Digester] Help please

Posted by Jose' Antonio Pe'rez Testa <ja...@indra.es>.
There are some errors of sintaxis in the example, but the more relevant 
inconsistence is

public setName(name){
   name=this.name;
  }

It must be

public setName(String name){
   this.name=name;
  }



Aristos Stavrou wrote:

>Could you please help me on the following problem?
>
>
>If I have an xml file containing the following element:
>...
>    <author name="....">
>        <address> ... </address>
>    </author>
>....
>
>and I have the following class defined for author element:
>
>public class Author{
>  private string name;
>  private string address;
>
>  public setName(name){
>   name=this.name;
>  }
>  public getName(){
>   return this.name;
>  }
>  public setAddress(addr){
>   this.address=addr;
>  }
>  public getAddress(){
>   return this.address;
>  }
>
>}
>
>how do I say digester parser to set the "name" property of the stack top
>object equal to the value of the "name" attribute of the author element.
>I have tried:
>addSetProperty(*/author, "name", "name");
>but it doesn?t work. Is this the right rule?
>
>
>Thanks in advance,
>Aristos
>
>
>---------------------------------------------------------------------
>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] Help please

Posted by Aristos Stavrou <cs...@cs.ucy.ac.cy>.
 Dear Antonio, Simon and Adrian ,

Thank you very much for your help.


----- Original Message ----- 
From: "Adrian Perez Jorge" <ap...@ignos.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Wednesday, April 21, 2004 12:08 PM
Subject: Re: [Digester] Help please


> Simon Kitching wrote:
>
> >On Wed, 2004-04-21 at 02:30, Aristos Stavrou wrote:
> >
> >
> >>Could you please help me on the following problem?
> >>
> >>
> >>If I have an xml file containing the following element:
> >>...
> >>    <author name="....">
> >>        <address> ... </address>
> >>    </author>
> >>....
> >>
> >>and I have the following class defined for author element:
> >>
> >>public class Author{
> >>  private string name;
> >>  private string address;
> >>
> >>  public setName(name){
> >>   name=this.name;
> >>  }
> >>  public getName(){
> >>   return this.name;
> >>  }
> >>  public setAddress(addr){
> >>   this.address=addr;
> >>  }
> >>  public getAddress(){
> >>   return this.address;
> >>  }
> >>
> >>}
> >>
> >>how do I say digester parser to set the "name" property of the stack top
> >>object equal to the value of the "name" attribute of the author element.
> >>I have tried:
> >>addSetProperty(*/author, "name", "name");
> >>but it doesn?t work. Is this the right rule?
> >>
> >>
> >
> >No, it's not the right rule to use for this.
> >
> >You can use the SetPropertiesRule, which tries to map all xml attributes
> >to matching set methods on the top object:
> >  digester.addSetProperties("*/author");
> >
> >Or you can use the CallMethodRule:
> >  digester.addCallMethod("*/author", "setName", 1);
> >  digester.addCallParam("*/author", 0, "name");
> >
> >Regards,
> >
> >Simon
> >
> >
> >
>   If you, Aristos, look at the example file
> `jakarta-commons/digester/src/examples/api/catalog/CatalogDigester.java'
> in the CVS repository, you will get the idea behind addSetProperty.
>
> Comments in that example source code say:
>
>         // Each tag of form "<attr id="foo" value="bar"/> needs to map
>         // to a call to setFoo("bar").
>
> And also this:
>
>         // Note that despite the name similarity, there is no link
>         // between SetPropertyRule and SetPropertiesRule.
>
> Cheers,
>
> Adrian P.J.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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


Re: [Digester] Help please

Posted by Adrian Perez Jorge <ap...@ignos.com>.
Simon Kitching wrote:

>On Wed, 2004-04-21 at 02:30, Aristos Stavrou wrote:
>  
>
>>Could you please help me on the following problem?
>>
>>
>>If I have an xml file containing the following element:
>>...
>>    <author name="....">
>>        <address> ... </address>
>>    </author>
>>....
>>
>>and I have the following class defined for author element:
>>
>>public class Author{
>>  private string name;
>>  private string address;
>>
>>  public setName(name){
>>   name=this.name;
>>  }
>>  public getName(){
>>   return this.name;
>>  }
>>  public setAddress(addr){
>>   this.address=addr;
>>  }
>>  public getAddress(){
>>   return this.address;
>>  }
>>
>>}
>>
>>how do I say digester parser to set the "name" property of the stack top
>>object equal to the value of the "name" attribute of the author element.
>>I have tried:
>>addSetProperty(*/author, "name", "name");
>>but it doesn?t work. Is this the right rule?
>>    
>>
>
>No, it's not the right rule to use for this.
>
>You can use the SetPropertiesRule, which tries to map all xml attributes
>to matching set methods on the top object:
>  digester.addSetProperties("*/author");
>
>Or you can use the CallMethodRule:
>  digester.addCallMethod("*/author", "setName", 1);
>  digester.addCallParam("*/author", 0, "name");
>
>Regards,
>
>Simon
>
>  
>
  If you, Aristos, look at the example file 
`jakarta-commons/digester/src/examples/api/catalog/CatalogDigester.java' 
in the CVS repository, you will get the idea behind addSetProperty.

Comments in that example source code say:

        // Each tag of form "<attr id="foo" value="bar"/> needs to map
        // to a call to setFoo("bar").

And also this:

        // Note that despite the name similarity, there is no link
        // between SetPropertyRule and SetPropertiesRule.

Cheers,

Adrian P.J.

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


Re: [Digester] Help please

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Wed, 2004-04-21 at 02:30, Aristos Stavrou wrote:
> Could you please help me on the following problem?
> 
> 
> If I have an xml file containing the following element:
> ...
>     <author name="....">
>         <address> ... </address>
>     </author>
> ....
> 
> and I have the following class defined for author element:
> 
> public class Author{
>   private string name;
>   private string address;
> 
>   public setName(name){
>    name=this.name;
>   }
>   public getName(){
>    return this.name;
>   }
>   public setAddress(addr){
>    this.address=addr;
>   }
>   public getAddress(){
>    return this.address;
>   }
> 
> }
> 
> how do I say digester parser to set the "name" property of the stack top
> object equal to the value of the "name" attribute of the author element.
> I have tried:
> addSetProperty(*/author, "name", "name");
> but it doesn?t work. Is this the right rule?

No, it's not the right rule to use for this.

You can use the SetPropertiesRule, which tries to map all xml attributes
to matching set methods on the top object:
  digester.addSetProperties("*/author");

Or you can use the CallMethodRule:
  digester.addCallMethod("*/author", "setName", 1);
  digester.addCallParam("*/author", 0, "name");

Regards,

Simon



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