Hi Tushar,
looks like you misinterpreted the SetProperty rule, read the
javadoc[1] for its description.
What would fit for your case is the SetPropertiesRule[2], so your code
should be changed to

private static void addRules(Digester digester)
{
    digester.addObjectCreate( "foo", "mypackage.Foo" );
    digester.addSetProperties( "foo", "fooName", "name" );
}

HTH, have a nice day!
Simo

[1] http://s.apache.org/G2t
[2] http://s.apache.org/DuX

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Sun, Sep 25, 2011 at 2:37 PM, tushar mishra <tush_mis...@yahoo.co.in> wrote:
>
>
>
>
> ________________________________
> From: tushar mishra <tush_mis...@yahoo.co.in>
> To: "user@commons.apache.org" <user@commons.apache.org>
> Sent: Sunday, 25 September 2011 4:36 PM
> Subject: problem with SetPropertyRule
>
>
> Hi,
>
> I am facing problem running a simple example using digester.
> Reference - http://commons.apache.org/digester/guide/core.html
>
> File Name - foo.xml
> <?xml version='1.0'?>
> <foo fooName="The Parent">
>     <bar id="123" title="The First Child" />
>     <bar id="456" title="The Second Child" />
> </foo>
> File Name - Foo.javapackage mypackage;
>
> import java.util.Iterator;
>
> public class Foo
> {String name;public String getName(){
> return name;
> }
>
> public void setName(String name)
> {
> this.name = name;
> }
> }
> File Name - Client.java
> package mypackage;
>
> import org.apache.commons.digester3.Digester;
>
> public class Client
> {
> public static void main(String[] args)
> {
> String filename = "C:\\development\\projects\\test\\resources\\foo.xml";
> Foo foo = null;
> Digester d = new Digester();
> d.setValidating(false);
> addRules(d);
>
> // Process the input file.
> try
> {
> java.io.File srcfile = new java.io.File(filename);
> foo = (Foo) d.parse(srcfile);
> }
> catch (java.io.IOException ioe)
> {
> System.out.println("Error reading input file:" + ioe.getMessage());
> System.exit(-1);
> }
> catch (org.xml.sax.SAXException se)
> {
> System.out.println("Error parsing input file:" + se.getMessage());
> System.exit(-1);
> }
>
> System.out.println(foo.getName());
> }
>
> private static void addRules(Digester digester)
> {
> digester.addObjectCreate("foo", "mypackage.Foo");
> digester.addSetProperty("foo", "fooName", "name");}
> }
>
> Output
>
> Error parsing input file:Error at line 2 char 27: Bean has no property named 
> The Parent
> Sep 25, 2011 4:12:48 PM org.apache.commons.digester3.Digester startElement
> SEVERE: Begin event threw exception
> java.lang.NoSuchMethodException:Bean has no property named The Parent
> at 
> org.apache.commons.digester3.SetPropertyRule.begin(SetPropertyRule.java:133)
> at org.apache.commons.digester3.Digester.startElement(Digester.java:1319)
>
> Question & Analysis
>
> Class - SetPropertyRule
>  if ( attributeName.equals( this.name ) )
>             {
>                 actualName = value;
>             }
> 1. What is this check for ? The documents gets parsed. It also finds the 
> attribute names correctly. But here, due to this condition, the attribute 
> name - fooName changes to "The Parent".
>
> What am I missing ?
>
> Thanks for your time.
> - Tushar

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

Reply via email to