为什么jsonix unmarshalling因人工URI而失败

时间:2016-09-13 23:41:44

标签: amazon-mws jsonix

在我尝试使用我创建的模式文件时ListMatchingProductsResponse.xsd,我遇到类似于another post的错误,但我不认为底层修复是一样的。< / p>

当我尝试解析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. ListMatchingProductsResponsehttp://mws.amazonservices.com/schema/Products/2011-10-01命名空间
  2. 联系起来
  3. 而我的架构将其与人工http://localhost:8000/ListMatchingProductsResponse.xsd命名空间联系起来,因为我是创建架构的人,并将ListMatchingProductsResponse定义为complexType
  4. 以下是我的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'
    },
    

    我试用的尝试&amp;错误:

    我真的不想改变响应,因为我真的无法控制它,但我通过修复命名空间是我的人为因素来查看事情是否会有所不同,但仍然导致相同的错误。 ..只是现在被抱怨的命名空间是不同的:

    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.
    

1 个答案:

答案 0 :(得分:2)

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

我至少看到了一些问题。

首先,我没有在您的架构中看到元素声明。你正试图解散 await具有ListMatchingProductsResponse命名空间,但在your schema中声明了哪里?

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

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

相关问题