5
有沒有辦法得到這個?JiBX解組 - 可以告訴JiBX忽略元素的順序嗎?
例如,我的XML:
<group>
<idExt>new group idext</idExt>
<user-id>1</user-id>
<parent-id>2</parent-id>
</group>
解組時
,不用錯誤,但是當我改變順序:
<group>
<user-id>1</user-id>
<parent-id>2</parent-id>
<idExt>new group idext</idExt>
</group>
失敗org.jibx.runtime.JiBXException: Expected "group" end tag, found "idExt" start tag (line 4, col 2)
。
我的解組(實現Struts2的ContentTypeHandler接口):
public void toObject(Reader in, Object target) {
try {
IBindingFactory bf = BindingDirectory.getFactory(target.getClass());
IUnmarshallingContext umc = bf.createUnmarshallingContext();
umc.setDocument(in);
// This un-conditional cast is the current way that JibX unmarshalls to an // already instantiated object - YUCK
((IUnmarshallable)target).unmarshal(umc);
} catch (JiBXException e) {
throw new RuntimeException(e);
}
}
和綁定:
<binding>
<mapping name="group" class="GroupVO" >
<value name="id" field="id" usage="optional"/>
<value name="idExt" field="idExt" usage="optional"/>
<value name="active" field="active" usage="optional"/>
<value name="created-at" field="dateCre" usage="optional"/>
<value name="updated-at" field="dateChg" usage="optional"/>
<value name="deleted-at" field="dateDel" usage="optional"/>
<value name="user-id" field="userId" usage="optional" />
<value name="parent-id" field="parentId" usage="optional" />
</mapping>
</binding>
所以,有可能的JiBX忽略標記順序?
簡單。有效。如果我只應該讀完它... – Trick 2010-02-19 13:31:57