Le format XML est prévu comme ci-dessous:Jsonix - Est-il possible de créer une collection et de déclarer 2 ou plusieurs éléments dans les déclarations de propriétés?
<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>
Le <a:condition>
et <operator>
tant besoin d'être dans un collection
que les deux peuvent avoir autant que requis par la requête XML.
ÉDITÉEType:elements
code comme ci-dessous:
{{
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);
}}
ÉDITÉ Ressemble elements
peut répondre à mes besoins. Unmarshalling fonctionne aussi. Maintenant, j'ai juste besoin de comprendre comment le marshall à partir du format Json. Tout conseil sera grandement apprécié
Merci. Vos guides étaient super! J'ai décidé d'utiliser 'elements'. J'ai édité mes questions. Maintenant, j'ai des problèmes avec le bon format JSON pour marshaling JSON en XML. – codingKit
Ceci est une autre question. – lexicore