首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么jsonix解编组对人工URI失败

为什么jsonix解编组对人工URI失败
EN

Stack Overflow用户
提问于 2016-09-13 23:41:43
回答 1查看 208关注 0票数 2

在尝试使用我创建的模式文件:ListMatchingProductsResponse.xsd时,我遇到了一个类似于另一个职位的错误,但我不认为底层修复是相同的。

当我试图解析一个样本响应

代码语言:javascript
复制
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);
  });
});

最后,我:

代码语言:javascript
复制
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. ListMatchingProductsResponsehttp://mws.amazonservices.com/schema/Products/2011-10-01命名空间联系起来
  2. 而我的模式将它与人工的http://localhost:8000/ListMatchingProductsResponse.xsd命名空间联系在一起,因为我是创建模式并将ListMatchingProductsResponse定义为complexType的人。

下面是我的映射/ListMatchingProductsResponse.js文件的摘录,它是在运行后生成的:java -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar -d mappings -p ListMatchingProductsResponse cache/xsd/localhost_8000/ListMatchingProductsResponse.xsd

代码语言:javascript
复制
{
    localName: 'ListMatchingProductsResponse',
    typeName: {
      namespaceURI: 'http:\/\/localhost:8000\/ListMatchingProductsResponse.xsd',
      localPart: 'ListMatchingProductsResponse'
},

我试错的尝试:

我真的不想改变响应,因为我真的无法控制它,但我摆弄它,看看通过将名称空间修复为我的人工名称是否会有所不同,但这仍然导致相同的错误.只是现在被抱怨的名称空间是不同的:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-14 09:05:45

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

我至少看到了一些问题。

首先,我看不到模式中的元素声明。您正在尝试用ListMatchingProductsResponse命名空间对http://mws.amazonservices.com/schema/Products/2011-10-01进行封送,但是它在您的模式中声明在哪里?

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

因此,据我所知,您的模式不完整,XML也不匹配。我可能错了(我必须分析所有的导入才能确定),但我认为您需要添加全局元素并检查名称空间。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39480513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档