hi brad
i think that what's happening is that you're pushing one instance of your
bean onto the stack at the start . you then have an object create rule
which creates a second instance of the bean which will then be populated
since it's the top one on the stack (at that time). the object you're
popping at the end is the one that you push on at the start.
try removing the object create rule and see if it starts working.
- robert
On Tuesday, July 2, 2002, at 09:46 PM, Brad Jones wrote:
> I am new to XML parsing (from an xml file to a Java object) and I'm
> trying out Digester.
> I'm having trouble figuring out how to use the digester to access the
> parsed XML once i've run the digester.parse() method. FYI...The
> following examples are just testing code for me to learn digester so
> things like Exception handling are not fully written.
>
> Here's a very simple xml file that I"m parsing:
>
> <toplevel>
> <element>
> <field1>Value 1</field1>
> <field2>Value 2</field2>
> </element>
> </toplevel>
>
> TestPropertyBean tpbean = new TestPropertyBean();
>
> java.io.FileInputStream fileInputStream = null;
> Digester digester = new Digester();
>
> //Adding data structure to digester to be parsed
> digester.push(tpbean);
>
> digester.setValidating(false);
>
> //Rules for parsing the xml file.
> digester.addObjectCreate("toplevel/element",
> "com.ibm.us.force.bean.property.TestPropertyBean");
> digester.addCallMethod("toplevel/element/field1","setField1",1);
> digester.addCallParam("toplevel/element/field1", 0);
> digester.addCallMethod("toplevel/element/field2","setField2",1);
> digester.addCallParam("toplevel/element/field2", 0);
>
> try {
> fileInputStream = new java.io.FileInputStream(name);
> } catch (java.io.FileNotFoundException fnfe) {
> //asdf
> }
>
> try {
> Object data = digester.parse(fileInputStream);
> TestPropertyBean tpbean2 = (TestPropertyBean)data;
> fileInputStream.close();
> } catch (org.xml.sax.SAXException se) {
> //asdf
> System.out.println(se.getMessage());
> } catch (java.io.IOException ie) {
> //asdf
> }
>
> When the digester.parse() method is called, I can see the
> TestPropertyBean setters being called and the values being set to the
> bean instance. My problem is that I don't know how to get access to that
> data once it's been parsed. I put break points in my setters on my bean
> and they are being called so I know that the data is being parsed from
> the XML to the bean but then I can't seem to get the "populated" object
> to return because when I cast to a TestPropertyBean the values are equal
> to null not "value 1", "value 2".
> I think it's a problem with the rules that I've written but I can't seem
> to figure out the correct combination.
>
> any suggestions would be greatly appreciated.
>
> Brad
>
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED].
> org>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED].
> org>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>