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ターゲット namespaceがあります。要素にはhttp://mws.amazonservices.com/schema/Products/2011-10-01名前空間があります。これは疑わしい。それが間違っていると言っているわけではありませんが (グローバル要素宣言がないため)、スキーマの場所と名前空間の URI が混在していると思います。

あなたのスキーマが完全ではなく、XML がそれに一致していないと私が言える限りでは。私は間違っているかもしれません (確かにすべてのインポートを分析する必要があります) が、グローバル要素を追加して名前空間を確認する必要があると思います。

于 2016-09-14T09:05:45.223 に答える