2

在我尝试使用我创建的架构文件: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.

我的怀疑:

到目前为止,我已经尝试了各种非智能黑客,但只是不明白这里的问题是什么。希望有更好的鹰眼观点和理解的人可以提供帮助。

对我来说最清楚的是样本响应

  1. 与命名空间ListMatchingProductsResponse的关系http://mws.amazonservices.com/schema/Products/2011-10-01
  2. 而我的架构将其与人工http://localhost:8000/ListMatchingProductsResponse.xsd命名空间相关联,因为我是创建架构并将其定义ListMatchingProductsResponsecomplexType.

以下是运行后生成的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.
4

1 回答 1

2

免责声明:我是Jsonix的作者。

我至少看到了一些问题。

首先,我在您的架构中看不到元素声明。您正在尝试 ListMatchingProductsResponse使用命名空间解组,但它在您的架构http://mws.amazonservices.com/schema/Products/2011-10-01中声明在哪里?

接下来,您的架构作为http://localhost:8000/ListMatchingProductsResponse.xsd目标命名空间。您的元素具有http://mws.amazonservices.com/schema/Products/2011-10-01命名空间。这是可疑的。我并不是说这是错误的(因为没有全局元素声明),但我猜你是在混合模式位置和命名空间 URI。

据我所知,您的架构不完整并且您的 XML 与它不匹配。我可能错了(我必须分析所有导入以确定),但我认为您需要添加全局元素并检查命名空间。

于 2016-09-14T09:05:45.223 回答