尝试四处寻找解决方案,但找不到任何简单的方法将属性添加到beanIO 1.2中的根xml标记中。
我需要实现以下内容:
<?xml version='1.0' encoding='utf-8'?>
<MyRootNode clientCode="German" recordCount="1">
<referrals>
<Individual>
<indvId>50853</indvId>
<firstName>Dad</firstName>
<middleName/>
<lastName>Test</lastName>
<suffixName/>
<gender>M</gender>
<race>WH</race>
<ethnicity>UN</ethnicity>
<DOB>2000-02-02</DOB>
<caseNumber>710645</caseNumber>
</Individual>
</referrals>
</MyRootNode>
到目前为止,我的beanio映射文件看起来像:
<stream name="MyRootNode" format="xml">
<record name="referrals" class="example.test.TestBean">
<bean name="individual" class="example.test.Individual" xmlName="Individual">
<field name="indvId" />
<field name="firstName" minOccurs="1" />
<field name="middleName" minOccurs="1" />
<field name="lastName" minOccurs="1" />
<field name="suffixName" minOccurs="1" />
<field name="gender" minOccurs="1" />
<field name="race" minOccurs="1" />
<field name="ethnicity" minOccurs="1" />
<field name="DOB" minOccurs="1" />
<field name="caseNumber" minOccurs="1" />
</bean>
</record>
</stream>
需要将clientCode="German" recordCount="1"
添加到MyRootNode。
感谢你的帮助!
谢谢&当做Rajiv
通过以下更改应该可以做到:
<stream format="xml" name="MyRootNode" xmlType="none">
<record class="example.test.TestBean" name="MyRootNode">
<field name="clientCode" xmlType="attribute"/>
<field name="recordCount" xmlType="attribute"/>
<segment name="referrals">
<bean class="example.test.Individual" name="individual" xmlName="Individual">
<field name="indvId"/>
<field minOccurs="1" name="firstName"/>
<field minOccurs="1" name="middleName"/>
<field minOccurs="1" name="lastName"/>
<field minOccurs="1" name="suffixName"/>
<field minOccurs="1" name="gender"/>
<field minOccurs="1" name="race"/>
<field minOccurs="1" name="ethnicity"/>
<field minOccurs="1" name="DOB"/>
<field minOccurs="1" name="caseNumber"/>
</bean>
</segment>
</record>
</stream>
说明:
- 流不再作为XML元素生成
- 第一个记录元素现在是"MyRootNode",它添加了属性