Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:02:10+00:00 2026-05-13T14:02:10+00:00

I have this XML that I want to be able to pull out the

  • 0

I have this XML that I want to be able to pull out the Order#, Item(s), Qty, ItemPrice (Principal, Tax, could be others as well). Here is the XML (see below). What I am having problems with is wiht the ItemPrice. With in it you can 0 to Many Price Components, Tax, Principal Etc. How can I pull those out into a single line output?

Right Now I can get orderNumber, ItemNumber, Qty…but when i pull the Price I get a line for tax and prinicpal.

One other question is what happens if in some instances Tax isn’t there? I will get a null reference won’t I? I want to try and handle those and just substitute 0. Any suggestions are greatly appreicated.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<SettlementReport>
<Order>
  <AmazonOrderID>105-6982537-6258888</AmazonOrderID> 
  <ShipmentID>MyShipmentIDTest1234</ShipmentID> 
  <MarketplaceName>Amazon.com</MarketplaceName> 
    <Fulfillment>
      <MerchantFulfillmentID>MyTestFulFillID12345</MerchantFulfillmentID> 
      <PostedDate>2008-12-15T19:33:04+00:00</PostedDate> 
        <Item>
          <AmazonOrderItemCode>13350774331938</AmazonOrderItemCode> 
          <SKU>U1409</SKU> 
          <Quantity>1</Quantity> 
            <ItemPrice>
                <Component>
                      <Type>Principal</Type> 
                      <Amount currency="USD">0.15</Amount> 
                  </Component>
                <Component>
                      <Type>Tax</Type> 
                      <Amount currency="USD">0.02</Amount> 
                  </Component>
              </ItemPrice>
          </Item>
          <Item>
            <AmazonOrderItemCode>13350774331939</AmazonOrderItemCode> 
            <SKU>U14010</SKU> 
            <Quantity>2</Quantity> 
            <ItemPrice>
                <Component>
                      <Type>Principal</Type> 
                      <Amount currency="USD">0.30</Amount> 
                  </Component>
                <Component>
                      <Type>Tax</Type> 
                      <Amount currency="USD">0.04</Amount> 
                  </Component>
              </ItemPrice>
          </Item>
      </Fulfillment>
  </Order>
</SettlementReport>

My Code:

            XDocument customer = XDocument.Load(@"C:\LinqToXML.xml");

            var orders = from amznorders in customer.Root.Elements("Order")
                         from amznfulfill in amznorders.Elements("Fulfillment")
                         from amznitems in amznfulfill.Elements("Item")
                         from amznitemprc in amznitems.Elements("ItemPrice").Elements("Component")
                             select new
                                        {
                                            OrderNumber = (string)amznorders.Element("AmazonOrderID"),
                                            ItemNumber = (string)amznitems.Element("AmazonOrderItemCode"),
                                            QTY = (string)amznitems.Element("Quantity"),
                                            //This is where I need help...if type = Principal set PriceAmount else Set PriceTax?//
                                            PriceAmount = (string)amznitemprc.Element("Amount")
                                            //Address1 = (string)address1.Element("Address1")
                                     };

            foreach (var order in orders)
            {
                Console.WriteLine("Order: {0} ItemNumber: {1} QTY: {2} PriceAmount: {3} ", order.OrderNumber, order.ItemNumber, order.QTY, order.PriceAmount);

            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:02:10+00:00Added an answer on May 13, 2026 at 2:02 pm

    Doable, though admittedly a bit awkward. I’d probably use a pair of let variables hold the sub-components I want (assuming you only want those two specific values).

    Edited to remove the lets due to problem with the Where clause. I don’t think there’s a problem with the Where in the select, but it may have the same problem.

    var orders = from amznorders in customer.Root.Elements("Order")    
                 from amznfulfill in amznorders.Elements("Fulfillment")    
                 from amznitems in amznfulfill.Elements("Item")    
                 from amznitemprc in amznitems.Elements("ItemPrice").Elements("Component")    
                 select new    
                             {    
                                    OrderNumber = (string)amznorders.Element("AmazonOrderID"),    
                                    ItemNumber = (string)amznitems.Element("AmazonOrderItemCode"),    
                                    Qty = (string)amznitems.Element("Quantity"),
                                    PriceAmount = amznitemprc.Where(xe => xe.Element("Type").Value == "Principal").FirstOrDefault().Value,
                                    TaxAmount = amxnitemprc.Where(xe => xe.Element("Type").Value == "Tax").FirstOrDefault() == null ? string.Empty : amxnitemprc.Where(xe => xe.Element("Type").Value == "Tax").FirstOrDefault(),
                                    TotalItemPrice = amznitemprc.Sum(xe => decimal.Parse(xe.Element("Amount").Value)).ToString(),
                                    //Address1 = (string)address1.Element("Address1")    
                             };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I want to do is this: I have a pom.xml that depends on
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I have an XML that goes like this: <?xml version=1.0 encoding=utf-8 ?> <colors> <color
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have a bunch of XML that has lines that look like this <_char
I have a piece of XML that is structured similar to this: <root> <score
I have a function that loads in some XML that looks like this: private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.