3

我在通过亚马逊 MWS 向亚马逊提交订单确认时遇到了一些问题。

我提交的 XML 是:

<?xml version="1.0"?>
<AmazonEnvelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  <Header>
    <DocumentVersion>1.01</DocumentVersion>
    <MerchantIdentifier>F85S4E7G4FSE98</MerchantIdentifier>
   </Header>
   <MessageType>OrderAcknowledgment</MessageType>
   <Message>
    <MessageID>1</MessageID>
    <OrderAcknowledgment>
      <AmazonOrderID>654-8547853-2598634</AmazonOrderID>
      <MerchantOrderID>658795124</MerchantOrderID>
      <StatusCode>Success</StatusCode>
      <Item>
        <AmazonOrderItemCode>35287489587654</AmazonOrderItemCode>
        <MerchantOrderItemID>587487</MerchantOrderItemID>
        <AmazonOrderItemCode>35287489587655</AmazonOrderItemCode>
        <MerchantOrderItemID>587488</MerchantOrderItemID>
      </Item>
    </OrderAcknowledgment>
  </Message>
</AmazonEnvelope>

提交 XML 时,亚马逊返回的错误是:
错误 25:我们无法处理 XML 提要,因为一件或多件商品无效。请重新提交 Feed。

我按照Amazon 提供的XML 文档指南创建了 XML。

基于此 Stack Overflow 问题,多个项目的格式是正确的。

我已经对照 XSD 文件检查了我的数据,并且 XML 似乎有效
https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/OrderAcknowledgement.xsd
https:// /images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/amzn-base.xsd

我尝试使用 XML XSD 验证器来验证 XML,但它返回错误:
Src-resolve:无法将名称“AmazonOrderID”解析为 A(n)“元素声明”组件。

这个错误对我来说没有多大意义,但我相信它会被返回,因为我无法在验证器中正确引用许多其他 XSC。“AmazonOrderID”的限制位于 amzn-base.xsd 文件中,与我提供的 AmazonOrderID 匹配

<xsd:element name="AmazonOrderID">
  <xsd:simpleType>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\w{3}-\w{7}-\w{7}"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:element>

我尝试按顺序确认单个项目,以防多个项目的结构不正确
我尝试完全删除项目部分,因为我阅读了项目部分有时不需要
我尝试通过我创建的处理所有其他请求成功
我尝试通过亚马逊暂存器提交:https ://mws.amazonservices.co.uk/scratchpad/index.html

我尝试过的任何方法都没有解决这个问题,我完全没有想法
你能提供的任何帮助将不胜感激

谢谢

4

2 回答 2

4

I'm currently trying to get a hold of all necessary XSDs to actually validate MWS files, but with little luck so far. Most validators will choke if a single XSD is missing, even if its contents are not relevant to the file it is currently validating. Amazon sure does make it hard to actually validate stuff- unless I'm missing something obvious.

My interim solution is to use a "crippled" XSD that only links to other XSDs that I actually have a copy of. Using this file is not perfect, but better than nothing. The way these XSDs are nested, anything I can validate with my XSD is actually valid. The only downside is that valid XMLs exist that I cannot validate, that I have to live with.

Using this set of XSDs, I had to make the following changes to your XML in order to pass validation:

  1. Change the MessageType to OrderAcknowledgement (extra "e" after the g. whether you like that spelling may depend on which side of the pond you live, nevertheless the XSD commands that exact spelling)
  2. Change both opening and closing tags to OrderAcknowledgement (same as above)
  3. Splitting that one Item into two (the StackOverflow question you linked has it wrong)

(I started writing this answer under the impression of C. M. Serperg-McQueen getting the spelling mixed up... I just read it again, and as it turns out, he was spot on, and I'm should improve my reading skills)

The validator message regarding AmazonOrderID was misleading. It was most probably a result of that validator also missing parts of the XSD.

Just for the sake of completeness. This file passed the (crippled) validation:

<?xml version="1.0"?>
<AmazonEnvelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  <Header>
    <DocumentVersion>1.01</DocumentVersion>
    <MerchantIdentifier>F85S4E7G4FSE98</MerchantIdentifier>
   </Header>
   <MessageType>OrderAcknowledgement</MessageType>
   <Message>
    <MessageID>1</MessageID>
    <OrderAcknowledgement>
      <AmazonOrderID>654-8547853-2598634</AmazonOrderID>
      <MerchantOrderID>658795124</MerchantOrderID>
      <StatusCode>Success</StatusCode>
      <Item>
        <AmazonOrderItemCode>35287489587654</AmazonOrderItemCode>
        <MerchantOrderItemID>587487</MerchantOrderItemID>
      </Item>
      <Item>
        <AmazonOrderItemCode>35287489587655</AmazonOrderItemCode>
        <MerchantOrderItemID>587488</MerchantOrderItemID>
      </Item>
    </OrderAcknowledgement>
  </Message>
</AmazonEnvelope>
于 2013-02-22T01:04:48.737 回答
2

您说“我已经根据 XSD 文件检查了我的数据,并且 XML 似乎有效”,但是您提到的两个架构文档都没有声明您的最外层元素(也没有声明其他一些元素,但我不会打扰列表)。Amazon 告诉您的是 XML 实际上是无效的。

那么,您的任务是使用 XSD 验证器找出您提交的文档中的无效内容。为了使这项工作,您需要将验证器指向亚马逊验证器使用的架构文档,或者它们的副本——如果您使用的验证器找不到所有必要的声明(如其错误消息所述) ,那么它不太可能对您有帮助。

对于它的价值,我尝试使用您提到的文档引用的架构文档来验证您的数据(https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/ release_1_9/amzn-envelope.xsd),但文档 Amazon.xsd 和 MaterialHandling.xsd(由 Product.xsd 依次包含)似乎不是相关参考建议的位置。因此,从 Amazon 模式文档中整合一个工作模式可能需要比人们预期的更多的功课。

据我所知,您的 XML 文档的直接问题是:

  • MessageType 的内容拼写为“OrderAcknowledgement”而不是“OrderAcknowledgement”。
  • MessageType 之后的元素名为 OrderAcknowledgement;我猜你的意思是 OrderAcknowledgement。
  • 您的 Item 元素有多个订单商品代码,而不仅仅是一个;我想你的意思是

    <Item>
      <AmazonOrderItemCode>35287489587654</AmazonOrderItemCode>
      <MerchantOrderItemID>587487</MerchantOrderItemID>
    </Item>
    <Item>
      <AmazonOrderItemCode>35287489587655</AmazonOrderItemCode>
      <MerchantOrderItemID>587488</MerchantOrderItemID>
    </Item>
    

祝你好运。

于 2013-02-21T00:06:00.350 回答