【发布时间】:2020-06-16 12:12:18
【问题描述】:
我正在使用 C#,我想解析关系元素。
我想获得“MarketplaceId”(A1F83G8C2ARO7P)和“ASIN”(B076B1GP37)的价值
这是我的 XML。
<Relationships>
<VariationParent xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
<ASIN>B076B1GP37</ASIN>
</MarketplaceASIN>
</Identifiers>
</VariationParent>
</Relationships>
到目前为止,这是我的代码。
if (relationshipList.IsSetAny())
{
foreach(var relationship in relationshipList.Any)
{
string rxml = ProductsUtil.FormatXml((System.Xml.XmlElement)relationship);
XDocument xDoc = XDocument.Parse(rxml);
XNamespace ns = XNamespace.Get("http://mws.amazonservices.com/schema/Products/2011-10-01");
IEnumerable<object> relationships = xDoc.Descendants();
foreach (System.Xml.Linq.XElement xe in relationships)
{
string r_marketplaceId = (string)xe.Attribute("MarketplaceId");
string r_ASIN = (string)xe.Attribute("ASIN");
}
}
}
xe 上面是下面
<VariationParent xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
<ASIN>B076B1GP37</ASIN>
</MarketplaceASIN>
</Identifiers>
</VariationParent>
r_marketplaceId 和 r_ASIN 仍然是 Null 值。 任何意见和建议将不胜感激。
【问题讨论】: