反序列化 XML 时出现 "System.ArgumentException: 'Illegal characters in path.'" 错误
I am getting error as "System.ArgumentException: 'Illegal characters in path.'" while deserializing XML
我正在尝试使用 XML 反序列化将来自 API 的大型 XML 响应解析为 C# 对象,但出现错误 System.ArgumentException: 'illegal characters in path'
我试过的代码如下
// XML Response from API is stored in xml variable
string xml = Response.Content;
XmlSerializer deserializer = new XmlSerializer(typeof(AmazonEnvelope));
TextReader reader = new StreamReader(xml);
object obj = deserializer.Deserialize(reader);
AmazonEnvelope XmlData = (AmazonEnvelope)obj;
reader.Close();
类 基于 XML 响应,下面创建 类 以便反序列化。
[XmlRoot(ElementName = "Header")]
public class Header
{
[XmlElement(ElementName = "DocumentVersion")]
public string DocumentVersion { get; set; }
}
[XmlRoot(ElementName = "Address")]
public class Address
{
[XmlElement(ElementName = "City")]
public string City { get; set; }
[XmlElement(ElementName = "State")]
public string State { get; set; }
[XmlElement(ElementName = "PostalCode")]
public string PostalCode { get; set; }
[XmlElement(ElementName = "Country")]
public string Country { get; set; }
}
[XmlRoot(ElementName = "FulfillmentData")]
public class FulfillmentData
{
[XmlElement(ElementName = "FulfillmentChannel")]
public string FulfillmentChannel { get; set; }
[XmlElement(ElementName = "ShipServiceLevel")]
public string ShipServiceLevel { get; set; }
[XmlElement(ElementName = "Address")]
public Address Address { get; set; }
}
[XmlRoot(ElementName = "Amount")]
public class Amount
{
[XmlAttribute(AttributeName = "currency")]
public string Currency { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Component")]
public class Component
{
[XmlElement(ElementName = "Type")]
public string Type { get; set; }
[XmlElement(ElementName = "Amount")]
public Amount Amount { get; set; }
}
[XmlRoot(ElementName = "ItemPrice")]
public class ItemPrice
{
[XmlElement(ElementName = "Component")]
public List<Component> Component { get; set; }
}
[XmlRoot(ElementName = "Promotion")]
public class Promotion
{
[XmlElement(ElementName = "PromotionIDs")]
public string PromotionIDs { get; set; }
[XmlElement(ElementName = "ShipPromotionDiscount")]
public string ShipPromotionDiscount { get; set; }
[XmlElement(ElementName = "ItemPromotionDiscount")]
public string ItemPromotionDiscount { get; set; }
}
[XmlRoot(ElementName = "OrderItem")]
public class OrderItem
{
[XmlElement(ElementName = "AmazonOrderItemCode")]
public string AmazonOrderItemCode { get; set; }
[XmlElement(ElementName = "ASIN")]
public string ASIN { get; set; }
[XmlElement(ElementName = "SKU")]
public string SKU { get; set; }
[XmlElement(ElementName = "ItemStatus")]
public string ItemStatus { get; set; }
[XmlElement(ElementName = "ProductName")]
public string ProductName { get; set; }
[XmlElement(ElementName = "Quantity")]
public string Quantity { get; set; }
[XmlElement(ElementName = "ItemPrice")]
public ItemPrice ItemPrice { get; set; }
[XmlElement(ElementName = "Promotion")]
public Promotion Promotion { get; set; }
[XmlElement(ElementName = "NumberOfItems")]
public string NumberOfItems { get; set; }
[XmlElement(ElementName = "PriceDesignation")]
public string PriceDesignation { get; set; }
}
[XmlRoot(ElementName = "Order")]
public class Order
{
[XmlElement(ElementName = "AmazonOrderID")]
public string AmazonOrderID { get; set; }
[XmlElement(ElementName = "MerchantOrderID")]
public string MerchantOrderID { get; set; }
[XmlElement(ElementName = "PurchaseDate")]
public string PurchaseDate { get; set; }
[XmlElement(ElementName = "LastUpdatedDate")]
public string LastUpdatedDate { get; set; }
[XmlElement(ElementName = "OrderStatus")]
public string OrderStatus { get; set; }
[XmlElement(ElementName = "SalesChannel")]
public string SalesChannel { get; set; }
[XmlElement(ElementName = "FulfillmentData")]
public FulfillmentData FulfillmentData { get; set; }
[XmlElement(ElementName = "IsBusinessOrder")]
public string IsBusinessOrder { get; set; }
[XmlElement(ElementName = "IsSoldByAB")]
public string IsSoldByAB { get; set; }
[XmlElement(ElementName = "OrderItem")]
public List<OrderItem> OrderItem { get; set; }
[XmlElement(ElementName = "FulfilledBy")]
public string FulfilledBy { get; set; }
}
[XmlRoot(ElementName = "Message")]
public class Message
{
[XmlElement(ElementName = "Order")]
public Order Order { get; set; }
}
[XmlRoot(ElementName = "AmazonEnvelope")]
public class AmazonEnvelope
{
[XmlElement(ElementName = "Header")]
public Header Header { get; set; }
[XmlElement(ElementName = "MessageType")]
public string MessageType { get; set; }
[XmlElement(ElementName = "Message")]
public List<Message> Message { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "noNamespaceSchemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string NoNamespaceSchemaLocation { get; set; }
}
API 的 XML 回复如下。
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">\r\n<Header>\r\n <DocumentVersion>1.00</DocumentVersion>\r\n </Header>\r\n<MessageType>AllOrdersReport</MessageType>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>407-4867592-2717133</AmazonOrderID>\r\n <MerchantOrderID>407-4867592-2717133</MerchantOrderID>\r\n <PurchaseDate>2021-01-03T18:29:44+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-05T08:03:11+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>PATNA</City>\r\n <State>BIHAR</State>\r\n <PostalCode>800020</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>65393459928915</AmazonOrderItemCode>\r\n <ASIN>B07GMRJTS9</ASIN>\r\n <SKU>CT4G4DFS8266-01</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>Crucial RAM 4GB DDR4 2666 MHz CL19 Desktop Memory CT4G4DFS8266</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">1450.0</Amount>\r\n </Component>\r\n <Component>\r\n <Type>Shipping</Type>\r\n <Amount currency=\"INR\">40.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n <Promotion>\r\n <PromotionIDs>IN Core Free Shipping 2015/04/08 23-48-5-108</PromotionIDs>\r\n <ShipPromotionDiscount>40.0</ShipPromotionDiscount>\r\n </Promotion>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>408-5979374-7689108</AmazonOrderID>\r\n <MerchantOrderID>408-5979374-7689108</MerchantOrderID>\r\n <PurchaseDate>2021-01-03T18:29:31+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-04T05:33:41+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>bangalore</City>\r\n <State>KARNATAKA</State>\r\n <PostalCode>560013</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>15137904364451</AmazonOrderItemCode>\r\n <ASIN>B01KVHE7Q4</ASIN>\r\n <SKU>LHOBT6C2101-20</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>Lapcare CQ42 6-Cell Battery for HP Laptops</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">1474.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n <Promotion>\r\n <PromotionIDs>IN Core Free Shipping 2015/04/08 23-48-5-108</PromotionIDs>\r\n </Promotion>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>402-6447122-2319519</AmazonOrderID>\r\n <PurchaseDate>2021-01-02T10:38:25+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-02T10:56:16+00:00</LastUpdatedDate>\r\n <OrderStatus>Cancelled</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Merchant</FulfillmentChannel>\r\n <ShipServiceLevel>Standard</ShipServiceLevel>\r\n <Address>\r\n <City>UDAIPUR</City>\r\n <State>RAJASTHAN</State>\r\n <PostalCode>313002</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <FulfilledBy>Easy Ship</FulfilledBy>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>64569408711947</AmazonOrderItemCode>\r\n <ASIN>B07K1XZXJL</ASIN>\r\n <SKU>U0H96E</SKU>\r\n <NumberOfItems>1</NumberOfItems>\r\n <ProductName>HP Care Pack 1 Year Accidental Damage Protection ADP with Onsite Support Add-on Pack for Pavilion and X360 Laptops</ProductName>\r\n <Quantity>0</Quantity>\r\n </OrderItem>\r\n <OrderItem>\r\n <AmazonOrderItemCode>68114446086235</AmazonOrderItemCode>\r\n <ASIN>B001B2U5R4</ASIN>\r\n <SKU>U0H91E</SKU>\r\n <NumberOfItems>1</NumberOfItems>\r\n <ProductName>HP Care Pack 2 Years Additional Warranty Next Business Day Support and Onsite Service for HP Omen & Envy Laptop</ProductName>\r\n <Quantity>0</Quantity>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>406-0676704-1460352</AmazonOrderID>\r\n <MerchantOrderID>406-0676704-1460352</MerchantOrderID>\r\n <PurchaseDate>2021-01-01T17:58:26+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-02T07:27:17+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>BENGALURU</City>\r\n <State>KARNATAKA</State>\r\n <PostalCode>560051</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>65883701062139</AmazonOrderItemCode>\r\n <ASIN>B07Z87LXY1</ASIN>\r\n <SKU>F4-3600C16D-16GTZRC</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>G.Skill F4-3600C16D-16GTZRC Trident Z RGB DDR4-3600MHz CL16-19-19-39 1.35V 16GB (2x8GB) Memory</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">11699.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n </OrderItem>\r\n <OrderItem>\r\n <AmazonOrderItemCode>29991566012307</AmazonOrderItemCode>\r\n <ASIN>B089XVWVZ9</ASIN>\r\n <SKU>90MB1490-M0IAY0</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>ASUS TUF Gaming B550M-Plus AM4 PCIe 4.0 DDR4 (4600 O.C.) mATX Motherboard with 2.5Gb Ethernet WiFi 6 2X M.2 USB 3.2 Gen2 and Aura Sync RGB Support</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">15940.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n</AmazonEnvelope>\r\n"
请帮忙
使用XmlTextReader
using (var stringReader = new StringReader(xml))
{
using (var reader = new XmlTextReader(stringReader))
{
object obj = deserializer.Deserialize(reader);
AmazonEnvelope XmlData = (AmazonEnvelope)obj;
}
}
我正在尝试使用 XML 反序列化将来自 API 的大型 XML 响应解析为 C# 对象,但出现错误 System.ArgumentException: 'illegal characters in path'
我试过的代码如下
// XML Response from API is stored in xml variable
string xml = Response.Content;
XmlSerializer deserializer = new XmlSerializer(typeof(AmazonEnvelope));
TextReader reader = new StreamReader(xml);
object obj = deserializer.Deserialize(reader);
AmazonEnvelope XmlData = (AmazonEnvelope)obj;
reader.Close();
类 基于 XML 响应,下面创建 类 以便反序列化。
[XmlRoot(ElementName = "Header")]
public class Header
{
[XmlElement(ElementName = "DocumentVersion")]
public string DocumentVersion { get; set; }
}
[XmlRoot(ElementName = "Address")]
public class Address
{
[XmlElement(ElementName = "City")]
public string City { get; set; }
[XmlElement(ElementName = "State")]
public string State { get; set; }
[XmlElement(ElementName = "PostalCode")]
public string PostalCode { get; set; }
[XmlElement(ElementName = "Country")]
public string Country { get; set; }
}
[XmlRoot(ElementName = "FulfillmentData")]
public class FulfillmentData
{
[XmlElement(ElementName = "FulfillmentChannel")]
public string FulfillmentChannel { get; set; }
[XmlElement(ElementName = "ShipServiceLevel")]
public string ShipServiceLevel { get; set; }
[XmlElement(ElementName = "Address")]
public Address Address { get; set; }
}
[XmlRoot(ElementName = "Amount")]
public class Amount
{
[XmlAttribute(AttributeName = "currency")]
public string Currency { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Component")]
public class Component
{
[XmlElement(ElementName = "Type")]
public string Type { get; set; }
[XmlElement(ElementName = "Amount")]
public Amount Amount { get; set; }
}
[XmlRoot(ElementName = "ItemPrice")]
public class ItemPrice
{
[XmlElement(ElementName = "Component")]
public List<Component> Component { get; set; }
}
[XmlRoot(ElementName = "Promotion")]
public class Promotion
{
[XmlElement(ElementName = "PromotionIDs")]
public string PromotionIDs { get; set; }
[XmlElement(ElementName = "ShipPromotionDiscount")]
public string ShipPromotionDiscount { get; set; }
[XmlElement(ElementName = "ItemPromotionDiscount")]
public string ItemPromotionDiscount { get; set; }
}
[XmlRoot(ElementName = "OrderItem")]
public class OrderItem
{
[XmlElement(ElementName = "AmazonOrderItemCode")]
public string AmazonOrderItemCode { get; set; }
[XmlElement(ElementName = "ASIN")]
public string ASIN { get; set; }
[XmlElement(ElementName = "SKU")]
public string SKU { get; set; }
[XmlElement(ElementName = "ItemStatus")]
public string ItemStatus { get; set; }
[XmlElement(ElementName = "ProductName")]
public string ProductName { get; set; }
[XmlElement(ElementName = "Quantity")]
public string Quantity { get; set; }
[XmlElement(ElementName = "ItemPrice")]
public ItemPrice ItemPrice { get; set; }
[XmlElement(ElementName = "Promotion")]
public Promotion Promotion { get; set; }
[XmlElement(ElementName = "NumberOfItems")]
public string NumberOfItems { get; set; }
[XmlElement(ElementName = "PriceDesignation")]
public string PriceDesignation { get; set; }
}
[XmlRoot(ElementName = "Order")]
public class Order
{
[XmlElement(ElementName = "AmazonOrderID")]
public string AmazonOrderID { get; set; }
[XmlElement(ElementName = "MerchantOrderID")]
public string MerchantOrderID { get; set; }
[XmlElement(ElementName = "PurchaseDate")]
public string PurchaseDate { get; set; }
[XmlElement(ElementName = "LastUpdatedDate")]
public string LastUpdatedDate { get; set; }
[XmlElement(ElementName = "OrderStatus")]
public string OrderStatus { get; set; }
[XmlElement(ElementName = "SalesChannel")]
public string SalesChannel { get; set; }
[XmlElement(ElementName = "FulfillmentData")]
public FulfillmentData FulfillmentData { get; set; }
[XmlElement(ElementName = "IsBusinessOrder")]
public string IsBusinessOrder { get; set; }
[XmlElement(ElementName = "IsSoldByAB")]
public string IsSoldByAB { get; set; }
[XmlElement(ElementName = "OrderItem")]
public List<OrderItem> OrderItem { get; set; }
[XmlElement(ElementName = "FulfilledBy")]
public string FulfilledBy { get; set; }
}
[XmlRoot(ElementName = "Message")]
public class Message
{
[XmlElement(ElementName = "Order")]
public Order Order { get; set; }
}
[XmlRoot(ElementName = "AmazonEnvelope")]
public class AmazonEnvelope
{
[XmlElement(ElementName = "Header")]
public Header Header { get; set; }
[XmlElement(ElementName = "MessageType")]
public string MessageType { get; set; }
[XmlElement(ElementName = "Message")]
public List<Message> Message { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "noNamespaceSchemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string NoNamespaceSchemaLocation { get; set; }
}
API 的 XML 回复如下。
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">\r\n<Header>\r\n <DocumentVersion>1.00</DocumentVersion>\r\n </Header>\r\n<MessageType>AllOrdersReport</MessageType>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>407-4867592-2717133</AmazonOrderID>\r\n <MerchantOrderID>407-4867592-2717133</MerchantOrderID>\r\n <PurchaseDate>2021-01-03T18:29:44+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-05T08:03:11+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>PATNA</City>\r\n <State>BIHAR</State>\r\n <PostalCode>800020</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>65393459928915</AmazonOrderItemCode>\r\n <ASIN>B07GMRJTS9</ASIN>\r\n <SKU>CT4G4DFS8266-01</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>Crucial RAM 4GB DDR4 2666 MHz CL19 Desktop Memory CT4G4DFS8266</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">1450.0</Amount>\r\n </Component>\r\n <Component>\r\n <Type>Shipping</Type>\r\n <Amount currency=\"INR\">40.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n <Promotion>\r\n <PromotionIDs>IN Core Free Shipping 2015/04/08 23-48-5-108</PromotionIDs>\r\n <ShipPromotionDiscount>40.0</ShipPromotionDiscount>\r\n </Promotion>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>408-5979374-7689108</AmazonOrderID>\r\n <MerchantOrderID>408-5979374-7689108</MerchantOrderID>\r\n <PurchaseDate>2021-01-03T18:29:31+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-04T05:33:41+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>bangalore</City>\r\n <State>KARNATAKA</State>\r\n <PostalCode>560013</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>15137904364451</AmazonOrderItemCode>\r\n <ASIN>B01KVHE7Q4</ASIN>\r\n <SKU>LHOBT6C2101-20</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>Lapcare CQ42 6-Cell Battery for HP Laptops</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">1474.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n <Promotion>\r\n <PromotionIDs>IN Core Free Shipping 2015/04/08 23-48-5-108</PromotionIDs>\r\n </Promotion>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>402-6447122-2319519</AmazonOrderID>\r\n <PurchaseDate>2021-01-02T10:38:25+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-02T10:56:16+00:00</LastUpdatedDate>\r\n <OrderStatus>Cancelled</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Merchant</FulfillmentChannel>\r\n <ShipServiceLevel>Standard</ShipServiceLevel>\r\n <Address>\r\n <City>UDAIPUR</City>\r\n <State>RAJASTHAN</State>\r\n <PostalCode>313002</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <FulfilledBy>Easy Ship</FulfilledBy>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>64569408711947</AmazonOrderItemCode>\r\n <ASIN>B07K1XZXJL</ASIN>\r\n <SKU>U0H96E</SKU>\r\n <NumberOfItems>1</NumberOfItems>\r\n <ProductName>HP Care Pack 1 Year Accidental Damage Protection ADP with Onsite Support Add-on Pack for Pavilion and X360 Laptops</ProductName>\r\n <Quantity>0</Quantity>\r\n </OrderItem>\r\n <OrderItem>\r\n <AmazonOrderItemCode>68114446086235</AmazonOrderItemCode>\r\n <ASIN>B001B2U5R4</ASIN>\r\n <SKU>U0H91E</SKU>\r\n <NumberOfItems>1</NumberOfItems>\r\n <ProductName>HP Care Pack 2 Years Additional Warranty Next Business Day Support and Onsite Service for HP Omen & Envy Laptop</ProductName>\r\n <Quantity>0</Quantity>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n<Message>\r\n <Order>\r\n <AmazonOrderID>406-0676704-1460352</AmazonOrderID>\r\n <MerchantOrderID>406-0676704-1460352</MerchantOrderID>\r\n <PurchaseDate>2021-01-01T17:58:26+00:00</PurchaseDate>\r\n <LastUpdatedDate>2021-01-02T07:27:17+00:00</LastUpdatedDate>\r\n <OrderStatus>Shipped</OrderStatus>\r\n <SalesChannel>Amazon.in</SalesChannel>\r\n <FulfillmentData>\r\n <FulfillmentChannel>Amazon</FulfillmentChannel>\r\n <ShipServiceLevel>Expedited</ShipServiceLevel>\r\n <Address>\r\n <City>BENGALURU</City>\r\n <State>KARNATAKA</State>\r\n <PostalCode>560051</PostalCode>\r\n <Country>IN</Country>\r\n </Address>\r\n </FulfillmentData>\r\n <IsBusinessOrder>false</IsBusinessOrder>\r\n <IsSoldByAB>false</IsSoldByAB>\r\n <OrderItem>\r\n <AmazonOrderItemCode>65883701062139</AmazonOrderItemCode>\r\n <ASIN>B07Z87LXY1</ASIN>\r\n <SKU>F4-3600C16D-16GTZRC</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>G.Skill F4-3600C16D-16GTZRC Trident Z RGB DDR4-3600MHz CL16-19-19-39 1.35V 16GB (2x8GB) Memory</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">11699.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n </OrderItem>\r\n <OrderItem>\r\n <AmazonOrderItemCode>29991566012307</AmazonOrderItemCode>\r\n <ASIN>B089XVWVZ9</ASIN>\r\n <SKU>90MB1490-M0IAY0</SKU>\r\n <ItemStatus>Shipped</ItemStatus>\r\n <ProductName>ASUS TUF Gaming B550M-Plus AM4 PCIe 4.0 DDR4 (4600 O.C.) mATX Motherboard with 2.5Gb Ethernet WiFi 6 2X M.2 USB 3.2 Gen2 and Aura Sync RGB Support</ProductName>\r\n <Quantity>1</Quantity>\r\n <ItemPrice>\r\n <Component>\r\n <Type>Principal</Type>\r\n <Amount currency=\"INR\">15940.0</Amount>\r\n </Component>\r\n </ItemPrice>\r\n </OrderItem>\r\n </Order>\r\n</Message>\r\n</AmazonEnvelope>\r\n"
请帮忙
使用XmlTextReader
using (var stringReader = new StringReader(xml))
{
using (var reader = new XmlTextReader(stringReader))
{
object obj = deserializer.Deserialize(reader);
AmazonEnvelope XmlData = (AmazonEnvelope)obj;
}
}