按照使用 jsonix-schema-compiler 的说明,我成功获得了 xsd 文件的映射对象;其中非常概括的内容是:
var IdentPerson_Module_Factory = function () {
var IdentPerson = {
name: 'IdentPerson',
defaultElementNamespaceURI: 'http:\/\/www.some.domain.de\/mynamespace',
typeInfos: [{
....
....
}],
elementInfos: [{
elementName: 'Person',
typeInfo: '.Person'
}]
};
return {
IdentPerson: IdentPerson
};
};
现在我想使用 jsonix 和上面的 json-mapping-object 生成一个 xml-String:
var context = new Jsonix.Context([IdentPerson]);
var marshaller = context.createMarshaller();
var xmldoc = marshaller.marshalString(myJsonString);
myJsonString 的第一行如下:
{ Person:
{ aliasName:
{ titel: '',
namenssuffix: '',
familyname: [Object],
.....
.....
}
以错误结束:
Message: Element [Person] is not known in this context, could not determine its type.
Stack: Error: Element [Person] is not known in this context, could not determine its type.
at Object.Jsonix.Binding.Marshalls.Element.Jsonix.Class.marshalElement (/home/datarocket/datarocket.hub/src/node_modules/jsonix/jsonix.js:1881:10)
我猜这是因为 myJsonString 中缺少命名空间?如果是这样,我该如何解决?提前致谢;