在我尝试使用我创建的架构文件:ListMatchingProductsResponse.xsd时,我遇到了与另一篇文章类似的错误,但我认为底层修复不一样。
当我尝试解析示例响应时:
var ListMatchingProductsResponse = require('/mappings/ListMatchingProductsResponse').ListMatchingProductsResponse;
var Jsonix = require('jsonix').Jsonix;
var context = new Jsonix.Context([ListMatchingProductsResponse]);
var unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshalFile('sample-response.xml',
function (unmarshalled) {
console.log('unmarshalled:', unmarshalled);
});
});
我最终得到:
Uncaught Error:
Element [{http://mws.amazonservices.com/schema/Products/2011-10-01}ListMatchingProductsResponse]
could not be unmarshalled as is not known in this context
and the property does not allow DOM content.
我的怀疑:
到目前为止,我已经尝试了各种非智能黑客,但只是不明白这里的问题是什么。希望有更好的鹰眼观点和理解的人可以提供帮助。
对我来说最清楚的是样本响应
- 与命名空间
ListMatchingProductsResponse
的关系http://mws.amazonservices.com/schema/Products/2011-10-01
- 而我的架构将其与人工
http://localhost:8000/ListMatchingProductsResponse.xsd
命名空间相关联,因为我是创建架构并将其定义ListMatchingProductsResponse
为complexType
.
以下是运行后生成的mappings/ListMatchingProductsResponse.js文件的摘录:java -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar -d mappings -p ListMatchingProductsResponse cache/xsd/localhost_8000/ListMatchingProductsResponse.xsd
{
localName: 'ListMatchingProductsResponse',
typeName: {
namespaceURI: 'http:\/\/localhost:8000\/ListMatchingProductsResponse.xsd',
localPart: 'ListMatchingProductsResponse'
},
我的试错尝试:
我真的不想更改响应,因为我真的无法控制它,但我摆弄它,看看是否可以通过将命名空间修复为我的人造命名空间来改变它,但这仍然导致相同的错误......只是现在被抱怨的命名空间不同了:
Uncaught Error:
Element [{http://localhost:8000/ListMatchingProductsResponse.xsd}ListMatchingProductsResponse]
could not be unmarshalled as is not known in this context
and the property does not allow DOM content.