【问题标题】:Why jsonix unmarshalling fails for artificial URIs为什么人工 URI 的 jsonix 解组失败
【发布时间】:2016-09-13 23:41:43
【问题描述】:

在尝试使用我创建的架构文件:ListMatchingProductsResponse.xsd 时,我遇到了类似于 another post 的错误,但我认为底层修复不一样。

当我尝试解析 sample response:

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.

我的怀疑:

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

对我来说最明显的是sample response

  1. 将ListMatchingProductsResponse 与http://mws.amazonservices.com/schema/Products/2011-10-01 命名空间联系起来
  2. 而我的架构将其与人工的 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.

【问题讨论】:

    标签: amazon-mws jsonix


    【解决方案1】:

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

    我至少发现了一些问题。

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

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

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

    【讨论】:

    • complexType for ListMatchingProductsResponse 存在,但元素不存在。我会尝试更改。 gist.github.com/pulkitsinghal/… +1 对您关于“添加全局元素并检查命名空间”的建议,一旦我知道这是一个 xml 问题而不是 jsonix 问题,我就会将您的答案标记为已接受。感谢您的慷慨指导。
    • 不想让任何其他读者悬而未决...revision 6 的要点根据@lexicore 的建议对架构进行了修复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    相关资源
    最近更新 更多