Nice to hear that it finally worked, have a nice day! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/
On Mon, Sep 26, 2011 at 10:57 AM, tushar mishra <[email protected]> wrote: > Thanks much Simone !! > That works so good. I spent a day for this problem :) > > - Tushar > > > ________________________________ > From: Simone Tripodi <[email protected]> > To: Commons Users List <[email protected]> > Sent: Sunday, 25 September 2011 8:53 PM > Subject: Re: problem with SetPropertyRule > > 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 <[email protected]> > wrote: >> >> >> >> >> ________________________________ >> From: tushar mishra <[email protected]> >> To: "[email protected]" <[email protected]> >> 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: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
