我使用的是JSONIX 2.4.1并且令人惊叹。 我已经在互联网上搜索了很多关于此事的内容,但我无法使其发挥作用。
这是我的代码
var Jsonix = require('jsonix').Jsonix;
var CTeSchema = require('./mappings/CTe_v2').CTe_v2;
var fs = require('fs');
var context = new Jsonix.Context([CTeSchema], {
namespacePrefixes: {
"http://www.portalfiscal.inf.br/cte": ""
},
mappingStyle: 'simplified'
});
var marshaller = context.createMarshaller();
var jsObj = {
infModal: {
versaoModal: '2.00',
value: {
any: [{
name: {
localPart: 'rodo'
},
value: {
RTNC: '00000000'
},
value: {
dPrev: '2016-01-01'
},
value: {
lota: '0'
},
}]
}
}
};
var marshalledXML = marshaller.marshalString(jsObj);
fs.writeFileSync('./xml/output.xml', marshalledXML, [encoding = 'utf8']);
我需要输出结果,如XML
<infModal versaoModal="2.00">
<rodo>
<RNTRC>00000000</RNTRC>
<dPrev>2016-01-01</dPrev>
<lota>0</lota>
</rodo>
</infModal>
但我得到了这个
<infModal versaoModal="2.00"/>
{
name: 'infModal',
required: true,
typeInfo: '.TCTe.InfCte.InfCTeNorm.InfModal'
}, {
localName: 'TCTe.InfCte.InfCTeNorm.InfModal',
typeName: null,
propertyInfos: [{
name: 'any',
required: true,
allowTypedObject: false,
mixed: false,
type: 'anyElement'
}, {
name: 'versaoModal',
required: true,
attributeName: {
localPart: 'versaoModal'
},
type: 'attribute'
}]
}
请帮忙吗?