Spring Castor 使用映射解组

Spring Castor Unmarshalling with Mapping

我正在尝试使用 Spring 中的 Castor OXM Unmarshalling 将 XML 解组为对象。

XML:

<LevelA>
  <LevelB>
    <item name="itemA">value</item>
    <item name="itemB">value</item>
    <item name="itemC">value</item>
    <item name="itemD">value</item>
    <item name="itemE">value</item>
  </LevelB>
</LevelA>

Object:
 Class LevelA {
     LevelB objLevelB;
     //getter and setter
   }

 Class LevelB {
     List<Items> item = new ArrayList<Items>();
     //getter and setter
   }

 Class Items {
     String Name;
     String Value;
    //getter and setter
  }


 Castor Mapping: 

  <mapping>
    <class name="LevelA">
      <map-to xml="LevelA" />
      <field name="objLevelB" type="LevelB">
        <bind-xml name="LevelB" />
          <class name="LevelB">
           <field name="item" type="Items" collection="arraylist">
             <bind-xml name="item" node="element" />
                <class name="Items">
                  <field name="Name" type="string">
                    <bind-xml name="name" node="attribute" />
                  </field>
                  <field name="Value" type="string">
                    <bind-xml node="text" />
                  </field>
                 </class>
            </field>
          </class>
      </field>
    </class>
  </mapping> 

我收到以下错误:

org.xml.sax.SAXException: unable to find FieldDescriptor for 'item' in ClassDescriptor of LevelB

我已经尝试了几种方法并且花费了足够的时间,所以我现在需要你们的帮助。

任何帮助都会有用。

我自己想出了办法,这是对我有用的映射。我正在分享答案以帮助处于相同情况的其他人。

<?xml version="1.0" encoding="UTF-8"?>
<mapping>
    <description> Provides Mapping to Convert Document to POJO</description>
    <class name="LevelAClass">
        <map-to xml="LevelA" />
        <field name="objLevelB" type="LevelBClass">
            <bind-xml name="LevelB" />
        </field>
    </class>

    <class name="LevelBClass">
        <field name="item" type="LevelCClass"
            collection="arraylist">
            <bind-xml name="item" />
        </field>
    </class>

    <class name="LevelCClass">
        <field name="Name">
            <bind-xml name="name" node="attribute" />
        </field>
        <field name="Value">
            <bind-xml name="item" node="text" />
        </field>
    </class>
</mapping>