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 6124713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:09:50+00:00 2026-05-23T16:09:50+00:00

I have the following XML <OrderReport> <Item> <Promotion> <Component> <Type>Principal</Type> <Amount currency=USD>-0.25</Amount> </Component> <Component>

  • 0

I have the following XML

<OrderReport>
  <Item>
    <Promotion>      
      <Component>
        <Type>Principal</Type>
        <Amount currency="USD">-0.25</Amount>
      </Component>
      <Component>
        <Type>Shipping</Type>
        <Amount currency="USD">0.00</Amount>
      </Component>
    </Promotion>
  </Item>
</OrderReport>

I need to get the Amounts for each type. Below is what I’m trying

var q = from orders in xDoc.Descendants("OrderReport")    
        select new 
        {
            //This should return me the Principal Amount
            ItemDiscountAmount = orders.Element("Item")
                                       .Element("Promotion")
                                       .Element("Component")
                                       .Element("Amount")
                                       .Value,
            //This should return me the Principal Currency
            ItemDiscountCurrency = orders.Element("Item")
                                         .Element("Promotion")
                                         .Element("Component")
                                         .Element("Amount")
                                         .Attribute("currency")
                                         .Value,

            //This should return me the Shipping Amount
            ShipDiscountAmount = orders.Element("Item")
                                       .Element("Promotion")
                                       .Element("Component")
                                       .Element("Amount")
                                       .Value,
            //This should return me the Shipping Currency                        
            ShipDiscountCurrency = orders.Element("Item")
                                         .Element("Promotion")
                                         .Element("Component")
                                         .Element("Amount")
                                         .Attribute("currency")
                                         .Value,
        };

The code I have written is incorrect. It returns me Principal Amount and Currency for all the properties right now. The comments describe what should be returned in it for understanding purpose.
The query should basically return me the Prices and Currency depending on the <Type> node under <Component> node. Not sure how to put a condition in this case.

  • 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-23T16:09:51+00:00Added an answer on May 23, 2026 at 4:09 pm

    It would help if you first find the elements that contained the Principal type or Shipping type first, then get the desired values. I believe this is what you’re after.

    // using an XPATH will make this nicer to express
    var query = from report in xDoc.Descendants("OrderReport")
                let principalAmount = report.XPathSelectElement("./*/*/Component[Type='Principal']/Amount")
                let shippingAmount = report.XPathSelectElement("./*/*/Component[Type='Shipping']/Amount")
                select new
                {
                    ItemDiscountAmount = (decimal)principalAmount,
                    ItemDiscountCurrency = (string)principalAmount.Attribute("currency"),
                    ShipDiscountAmount = (decimal)shippingAmount,
                    ShipDiscountCurrency = (string)shippingAmount.Attribute("currency"),
                };
    

    Just remember to include the namespace System.Xml.XPath for this to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML loaded in an XMLElement like below: <related_id> <Item> <classification>Component</classification>
I have the following XML: <query> <param weight=0.3> <item type=1 low=18 hi=20 pos=1 />
I have following XML: <Library> <Item> <Field Name=Name>smooth</Field> <Field Name=File Type>mid</Field> <Field Name=File Size>60026</Field>
I have the following XML :- <inventory> <item> <name_element> <!--some structure--> </name_element> <some_element1>val1</some_element1> <some_element2>val2</some_element2>
I have the following XML Tag <price currency=euros>20000.00</price> How do I restrict the currency
I have following xml which same child element (Filed) and I want to get
I have the following xml sample: <items> <item> <item_id>1</item_id> <item_name>item 1</item_name> <group_id>1</group_id> <group_name>group 1</group_name>
I have the following XML retreived from webservices.How do i get the value of
I have following source xml <forms> <x> <y> <x-component select=foobar /> </y> </x> <component
I have the following XML layout for an item that I put in my

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.