我正在尝试使用amzn-envelope.xsd验证 Amazon XML Feed 请求,但遇到了架构问题,因为 amzn-envelope.xsd 通过包含的架构包含对amzn-base.xsd 的多个引用。
这是我的示例 XML 提要:
<AmazonEnvelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>A38Z13EKY7MB4Y</MerchantIdentifier>
</Header>
<MessageType>OrderFulfillment</MessageType>
<Message>
<MessageID>1</MessageID>
<OrderFulfillment>
<AmazonOrderID></AmazonOrderID>
<MerchantFulfillmentID>2148031177</MerchantFulfillmentID>
<FulfillmentDate>2013-06-25T09:54:22Z</FulfillmentDate>
<FulfillmentData>
<CarrierName>UKMail Business Class</CarrierName>
<ShippingMethod>CU - Next Day</ShippingMethod>
<ShipperTrackingNumber>30995140015293</ShipperTrackingNumber>
</FulfillmentData>
</OrderFulfillment>
</Message>
</AmazonEnvelope>
使用如下代码进行验证时:
SchemaAmazonEnvelopeURL = "https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/amzn-envelope.xsd";
XDocument xdoc = XDocument.Parse(xml_data);
bool success = false;
try
{
success = Validate(xdoc, SchemaAmazonEnvelopeURL);
}
catch (Exception ex)
{
log.Error("Failed to validate against AWS Schema\n\n" + ex.Message);
}
Assert.IsTrue(success, "Failed validation");
public bool Validate(XDocument xDocument, string xsdSchema)
{
bool success = true;
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("", xsdSchema);
// Validate
xDocument.Validate(schemas, (o, e) =>
{
throw e.Exception;
});
return success;
}
我收到以下错误:
complexType 'NoiseLevelDimension' 已被声明。
通过查看架构,我可以看到amzn-base.xsd通过其他包含的架构多次包含,这就是验证失败的原因。
我怎样才能解决这个问题?