【问题标题】:GetMatchingProductForIdResponse no expectedGetMatchingProductForIdResponse 没有预期
【发布时间】:2014-08-13 10:39:20
【问题描述】:

一段时间以来,我一直在尝试从 Amazon 读取响应,但似乎卡在了从 xml 文件读取响应的位置。

我已经尝试了同一件事的许多变体来让它工作,但它每次都在完全相同的点上摔倒。

下面是我目前正在测试的代码。

var doc = new XmlDocument();
doc.LoadXml(product.ToXML());

File.WriteAllText(@"D:\myFile.xml", doc.InnerXml);
var xRoot = new XmlRootAttribute();
xRoot.ElementName = "Product";

xRoot.IsNullable = true;
var serializer = new XmlSerializer(typeof(MarketplaceWebServiceProducts.Model.Product), xRoot);

using (var reader = XmlReader.Create(@"D:\myFile.xml"))
{
    //falls over here because of unexpected elements in the xml doc
    var info = (MarketplaceWebServiceProducts.Model.Product)serializer.Deserialize(reader);
}

异常信息是:

<GetMatchingProductForIdResponse xmlns='http://mws.amazonservices.com/schema/Products/2011-10-01'> was not expected.

有其他人对亚马逊的回复有这个问题吗?或者有谁知道我可以如何解决这个问题?

【问题讨论】:

    标签: c# .net xml amazon


    【解决方案1】:

    您只保存InnerXml 有什么特别的原因吗?以防万一您不知道,这将删除根节点并可能产生无效的 XML(例如,如果根节点有多个子节点)。

    尝试保存OuterXml

    File.WriteAllText(@"D:\myFile.xml", doc.OuterXml);
    

    如果这不是您面临的实际问题,您可能需要发布 myFile.xml 的内容。

    【讨论】:

      猜你喜欢
      • 2020-11-12
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2021-10-19
      • 2020-03-18
      相关资源
      最近更新 更多