Hi

first of all, there's absolutely no need to have container classes (and their corresponding mappings) for <Root> and <Sub>, when the location attribute could be used instead (please have a look at the reference guide for detailed explanations).

Second, for all Java classes you want to bind to a corresponding XML, you will have to use <map-to xml="..." /> definitions.

And most importantly, please read up on Castor XML and its functionality before asking questions about mapping problems.

<class name="org.test.C">
  <field name="C" type="org.test.C" collection="arraylist">
    <bind-xml name="C1" node="element" />
  </field>
</class>

Assuming that you have a class org.test.C that has a member declaration similar to

private List<C1> c1;

you need to map this member as follows:

  <field name="c1" type="org.test.C1" collection="arraylist">
    <bind-xml name="C1" />
  </field>

I hope this makes sense. If not, please have a look at http://www.castor.org for a general introduction to XML data binding.

Regards
Werner
On 29.07.2010 16:27, sric1 wrote:

Hello,

I am really struggling with castor. I am using castor 1.3.1. I have used
castor generated classes for mapping but i faced issues with class loader.
Now i am going to XML based mapping instead of generated classes. But could
not find enough information on mapping nested elements. Could anyone help me
with this.

Sample xml message:
<Root>
    <Sub>
        <C>
          <C1>
              <test1>ac6556979b44</test1>
              <test2 xsi:nil="true"/>
              <test3>message</test3>
              <test4 xsi:nil="true"/>
          </C1>
          <C1>
              <test1>b3quiqioe8ii</test1>
              <test2 xsi:nil="true"/>
              <test3>message2</test3>
              <test4 xsi:nil="true"/>
          </C1>
           <C1>
              <test1>naciehi6373</test1>
              <test2 xsi:nil="true"/>
              <test3>message3</test3>
              <test4 xsi:nil="true"/>
           </C1>
        </C>
      </Sub>
    </Root>


Here element "C" contains multiple(array of) C1 elements.

Mapping file:
<code>
<mapping xmlns="http://castor.exolab.org/";>
        <class name="org.test.Root">
                <map-to xml="Root" />
                <field name="Sub" type="org.test.Sub"
                        required="true">
                        <bind-xml name="Sub" node="element"/>
                </field>
        </class>

        <class name="org.test.Sub">
                <field name="Sub"
                        type="org.test.Sub" required="true">
                        <bind-xml name="C" node="element" />
                </field>
        </class>
        <class name="org.test.C">
                <field name="C"
                        type="org.test.C" required="false" 
collection="arraylist">
                        <bind-xml name="C1" node="element" />
                </field>
        </class>
        <class name="org.test.C1">
                <field name="test1" type="java.lang.String">
                        <bind-xml name="test1" node="element" />
                </field>
                <field name="test2" type="java.lang.String">
                        <bind-xml name="test2" node="element" />
                </field>
                <field name="test3" type="java.lang.String">
                        <bind-xml name="test3" node="element" />
                </field>
                <field name="test4" type="java.lang.String">
                        <bind-xml name="test4" node="element" />
                </field>
        </class>
</mapping>
</code>

I am getting all kinds of unmarshalling exceptions. Any help would be
greatly appreciated.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to