I want to retrieve the product info and store it in my collection IEnumerable. However, only the information for two products is being returned. I tried to change my code from Element to Elements but it just threw an error.
Orderlist.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListOrderItemsResponse
xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
<ListOrderItemsResult>
<AmazonOrderId>002-1893166-3105064</AmazonOrderId>
<OrderItems>
<OrderItem>
<ASIN>B00HUX1W1G</ASIN>
<SellerSKU>NX-CHAG-UT0Q</SellerSKU>
<OrderItemId>37783785306314</OrderItemId>
<Title>Polyethylene Glycol (Peg) 200, ACS, Reagent Grade, One Quart Bottle</Title>
<QuantityOrdered>1</QuantityOrdered>
<QuantityShipped>0</QuantityShipped>
<ItemPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>25.00</Amount>
</ItemPrice>
<ShippingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>27.00</Amount>
</ShippingPrice>
<GiftWrapPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapPrice>
<ItemTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ItemTax>
<ShippingTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingTax>
<GiftWrapTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapTax>
<ShippingDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingDiscount>
<PromotionDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</PromotionDiscount>
<PromotionIds />
<ConditionNote>Alliance Chemical</ConditionNote>
<ConditionId>New</ConditionId>
<ConditionSubtypeId>New</ConditionSubtypeId>
</OrderItem>
</OrderItems>
</ListOrderItemsResult>
<ListOrderItemsResult>
<AmazonOrderId>102-5169016-4946643</AmazonOrderId>
<OrderItems>
<OrderItem>
<ASIN>B00OKOU4GM</ASIN>
<SellerSKU>35-9988-XJB8</SellerSKU>
<OrderItemId>23504328079730</OrderItemId>
<Title>Nitric Acid 65%, Acs, Reagent Grade, Quart(1 liter) Glass Bottle</Title>
<QuantityOrdered>1</QuantityOrdered>
<QuantityShipped>0</QuantityShipped>
<ItemPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>48.00</Amount>
</ItemPrice>
<ShippingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>27.00</Amount>
</ShippingPrice>
<GiftWrapPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapPrice>
<ItemTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ItemTax>
<ShippingTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingTax>
<GiftWrapTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapTax>
<ShippingDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingDiscount>
<PromotionDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</PromotionDiscount>
<PromotionIds />
<ConditionId>New</ConditionId>
<ConditionSubtypeId>New</ConditionSubtypeId>
</OrderItem>
<OrderItem>
<ASIN>B00D6JGB2S</ASIN>
<SellerSKU>DB-ZAYD-0QYZ</SellerSKU>
<OrderItemId>58842277149658</OrderItemId>
<Title>HYDROCHLORIC ACID 20 Be. Technical grade-One gallon bottle</Title>
<QuantityOrdered>1</QuantityOrdered>
<QuantityShipped>0</QuantityShipped>
<ItemPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>35.00</Amount>
</ItemPrice>
<ShippingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>27.00</Amount>
</ShippingPrice>
<GiftWrapPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapPrice>
<ItemTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ItemTax>
<ShippingTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingTax>
<GiftWrapTax>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</GiftWrapTax>
<ShippingDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</ShippingDiscount>
<PromotionDiscount>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</PromotionDiscount>
<PromotionIds />
<ConditionId>New</ConditionId>
<ConditionSubtypeId>New</ConditionSubtypeId>
</OrderItem>
</OrderItems>
</ListOrderItemsResult>
<ResponseMetadata>
<RequestId>b4d81fad-7d09-4e07-b166-e5638292d56d</RequestId>
</ResponseMetadata>
</ListOrderItemsResponse>
Code in Main
path = Path.Combine(Directory.GetCurrentDirectory(), "Orderlist.xml");
file = XDocument.Load(path);
xml = file.ToString();
doc = XDocument.Parse(xml);
var products = Products(doc);
private static IEnumerable<Address> Products(XContainer doc)
{
XNamespace ns = "https://mws.amazonservices.com/Orders/2013-09-01";
return from product in doc.Descendants(ns + "ListOrderItemsResult")
select new Address
{
Title = (string)product.Element(ns + "OrderItems").Element(ns + "OrderItem").Element(ns + "Title"),
ItemPrice = (string)product.Element(ns + "OrderItems").Element(ns + "OrderItem").Element(ns + "ItemPrice").Element(ns + "Amount"),
ShippingPrice = (string)product.Element(ns + "OrderItems").Element(ns + "OrderItem").Element(ns + "ShippingPrice").Element(ns + "Amount"),
Quantity = (string)product.Element(ns + "OrderItems").Element(ns + "OrderItem").Element(ns + "QuantityOrdered"),
P_OrderId = (string)product.Element(ns + "AmazonOrderId"),
};
}
public class Address
{
public string Name { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Title { get; set; }
public string ItemPrice { get; set; }
public string ShippingPrice { get; set; }
public string Quantity { get; set; }
public string P_OrderId { get; set; }
public string S_OrderId { get; set; }
public string PostalCode { get; set; }
}