You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Veerendra <ve...@cassis-intl.com> on 2005/04/08 08:34:22 UTC

Problem with Digester

Hi,
	I want to use digester frame work. I took some example from net modified
for my testing, but when I am not getting the result as null. if I use
uniqueid instead of UniqueID in xml it is working. is that case sensitive.
Can some body pls help me.

Thank You,
Veerenrda

Here is my programs.

Test.xml :

<?xml version="1.0" encoding="UTF-8"?>
<gp:academy UniqueID="JAcademy"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0">
</gp:academy>


package com.tesdig;
import java.util.Vector;

public class Academy {
    private String UniqueID;

    public Academy() {
    }

    public String getUniqueID() {
        return UniqueID;
    }

    public void setUniqueID(String newUniqueID) {
        UniqueID = newUniqueID;
    }

    public String toString() {
        StringBuffer buf = new StringBuffer(60);

        buf.append("Academy UniqueID>> " + this.getUniqueID());

        return buf.toString();
    }
}


package com.tesdig;

import java.io.File;
import org.apache.commons.digester.Digester;

public class DigestJavaAcademy {
    public static void main(String[] args) throws Exception {
        DigestJavaAcademy d = new DigestJavaAcademy();
        d.digest();
    }

    public void digest() throws Exception {
        Digester digester = new Digester();
        digester.setNamespaceAware(true);

        digester.addObjectCreate("academy", Academy.class);

        //Set the attribute values as properties
        digester.addSetProperties("academy");

        //Parse the XML file to get an Academy instance
        File input = new File( "academy.xml" );
        Academy a = (Academy) digester.parse(input);
        System.out.println(a);
    }
}


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


Re: Problem with Digester

Posted by Simon Kitching <sk...@apache.org>.
Hi Veerendra,

Veerendra wrote:
> Hi,
> 	I want to use digester frame work. I took some example from net modified
> for my testing, but when I am not getting the result as null. if I use
> uniqueid instead of UniqueID in xml it is working. is that case sensitive.
> Can some body pls help me.
> 
> Here is my programs.
> 
> Test.xml :
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <gp:academy UniqueID="JAcademy"
> xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0">
> </gp:academy>

The standard coding convention is for java bean property names to start 
with a *lower-case* letter.

property: "someProperty"
setter method name: "setSomeProperty"
getter method name: "getSomeProperty".

This is defined in detail in the java beans specification.

Digester expects the Java Beans specification to be followed. So when 
the input xml has an attribute "someProperty", the SetPropertiesRule 
will try to set a java bean property of name "someProperty" by calling a 
method of name "setSomeProperty".

The SetPropertiesRule constructor can take two arrays of strings to set 
up non-standard mappings from xml attribute name to java bean property 
name if you need this. There are a number of capitalisation conventions 
used in XML so it´s fairly common to need this (but Java code should 
always use the standard Java capitalisation conventions).

By the way, I am surprised that you say that using "uniqueid" in your 
input xml works; I believe this should cause a call to "setUniqueid" 
which doesn´t exist. Using "uniqueID" in your input xml should be the 
correct value (maps to a setter method "setUniqueID", whihc is what is 
defined on your class).

Regards,

Simon

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