Hello,

I'm trying to map the contents of an xml file to a HashMap. The XML-file looks 
like:

<seti>
        <chain index="CHN001" shortname="A1">
                <name>A1</name>
        </chain>
        <chain index="CHN002" shortname="A2">
                <name>A2</name>
        </chain>
        <chain index="CHN003" shortname="RpConf">
                <name>RC</name>
        </chain>
</seti>

and the java class is:

public class Seti implements java.io.Serializable {
    private HashMap chainList;

    public Seti() 
    {
        super();
        chainList = new HashMap();
    }

        public HashMap getChainList() {
                return chainList;
        }

        public void setChainList( HashMap chainList ) {
                this.chainList = chainList;
        }
}

It works if I use the attribute "index" as key and the child-element <name> as 
value of the Hash. The mapping looks then like this:

<?xml version="1.0" encoding="UTF-8"?>
<mapping xmlns="http://castor.exolab.org/";
        xmlns:cst="http://castor.exolab.org/";>
        <description>Castor generated mapping file</description>
        <class cst:name="com.infineon.pd.pt.tpec.setixml.Seti">
                <description>
                        Default mapping for class
                </description>
                <map-to cst:xml="seti"/>
                <field cst:name="chainList" cst:type="java.util.HashMap"
                        cst:collection="map">
                        <bind-xml name="chain">
                                <class name="org.exolab.castor.mapping.MapItem">
                                        <field name="key" 
type="java.lang.String">
                                                <bind-xml name="index" 
node="attribute" />
                                        </field>
                                        <field name="value" 
type="java.lang.String">
                                                <bind-xml name="name" 
node="element" />
                                        </field>
                                </class>
                        </bind-xml>
                </field>
        </class>
</mapping>

But what I really want is to have the chain class as the value of my hash. I 
tried to adapt the mapping file to achieve this:

<?xml version="1.0" encoding="UTF-8"?>
<mapping xmlns="http://castor.exolab.org/";
        xmlns:cst="http://castor.exolab.org/";>
        <description>Castor generated mapping file</description>
        <class cst:name="com.infineon.pd.pt.tpec.setixml.Seti">
                <description>
                        Default mapping for class
                </description>
                <map-to cst:xml="seti"/>
                <field cst:name="chainList" cst:type="java.util.HashMap"
                        cst:collection="map">
                        <bind-xml name="chain">
                                <class name="org.exolab.castor.mapping.MapItem">
                                        <field name="key" 
type="java.lang.String">
                                                <bind-xml name="index" 
node="attribute" />
                                        </field>
                                        <field name="value" 
type="com.infineon.pd.pt.tpec.setixml.Chain">
                                                <bind-xml name="chain" 
node="element" />
                                        </field>
                                </class>
                        </bind-xml>
                </field>
        </class>
        <class cst:name="com.infineon.pd.pt.tpec.setixml.Chain">
                <description>
                        Default mapping for class
                        com.infineon.pd.pt.tpec.setixml.Chain
                </description>
                <map-to cst:xml="chain"/>
                <field cst:name="index" cst:type="java.lang.String"
                        cst:required="true">
                        <bind-xml name="index" node="attribute" />
                </field>
                <field cst:name="shortname" cst:type="java.lang.String"
                        cst:required="true">
                        <bind-xml name="shortname" node="attribute" />
                </field>
                <field cst:name="name" cst:type="java.lang.String"
                        cst:required="true">
                        <bind-xml name="name" node="element" />
                </field>
        </class>
</mapping>

But this fails with the following error message:
unable to find FieldDescriptor for 'name' in ClassDescriptor of map-item{file: 
[not available]; line: 5; column: 9}

Does this mean I can't put the <chain> element as value into my hash? Does 
there exist a workaround?

Thanks,

Jörg Werner
-- 
Jörg Werner
Infineon Technologies AG 

-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to