预期的 XML 格式如下:
<c:condition>
<a:condition>
<fieldname>fieldName</fieldname>
<fieldtest>fieldTest</fieldtest>
<fieldvalues>
<fieldvalue>fieldValue</fieldvalue>
</fieldvalues>
</a:condition>
<operator>operator</operator>
<a:condition>
...<some>
</a:condition>
</c:condition>
和<a:condition>
两者<operator>
都需要在 acollection
中,因为两者都可以具有 XML 请求所需的数量。
编辑 Type:elements
代码如下:
{{
var MyModule = {
name: 'MyModule',
typeInfos: [{
type: 'classInfo',
localName: 'ElementsType',
propertyInfos: [{
type: 'elements',
name: 'c:condition',
wrapperElementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplex',
prefix: 'c'
},
collection: true,
elementTypeInfos: [{
elementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplexio',
prefix: 'a'
},
typeInfo: 'MyModule.SubAtomic'
}, {
elementName: 'operator',
typeInfo: 'String'
}]
}]
},
{
type: 'classInfo',
localName: 'SubAtomic',
propertyInfos:[{
type: 'element',
name: 'fieldName',
elementName: 'fieldName',
typeInfo: 'String'
},
{
type: 'element',
name: 'fieldTest',
elementName: 'fieldTest',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'root',
typeInfo: 'MyModule.ElementsType'
}]
};
console.log("creating unmarsaller");
var context = new Jsonix.Context([MyModule]);
var unmarshaller = context.createUnmarshaller();
var unmarshalled = unmarshaller.unmarshalString('<root><c:condition xmlns:c="http://us.xomplex"><a:condition xmlns:a="http://us.xomplexio">one</a:condition><operator>2</operator><a:condition xmlns:a="http://us.xomplexio"><fieldName>unmra</fieldName><fieldTest>Beneed</fieldTest></a:condition><a:condition xmlns:a="http://us.xomplexio">four</a:condition><operator>AND</operator><operator>4</operator></c:condition></root>');
console.log("unmarshalled");
console.log(unmarshalled);
var marshaller = context.createMarshaller();
var marshalled = marshaller.marshalString({
name: {
localPart: 'root'
},
//Marshalling - not working....
value: {
//'c:condition': ['one', 2, 'unmra', 'four', 10,4]
'c:condition': [
['Field','Test'],9
]
}
});
console.log(marshalled);
}}
EDITED看起来elements
可以满足我的要求。解组也有效。现在我只需要弄清楚如何从 Json 格式编组它。任何建议将不胜感激