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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:22:03+00:00 2026-06-17T06:22:03+00:00

hi all am trying to read a xml document using linq.am struck with a

  • 0

hi all am trying to read a xml document using linq.am struck with a problem a node has two values in the same name how can i get those two values. am able to get only the first using this code.

XDocument doc = XDocument.Load("Orders.xml");
var data = from item in doc.Descendants("Order")
           select new
           {
               OrderID = item.Element("OrderID").Value,
               POnumber = item.Element("PurchaseOrderNumber").Value,
               OrderDate = item.Element("OrderPlacedDate").Value,
               PFirstName = item.Element("purchasingContact").Element("FirstName").Value,
               Pid= item.Element("CurrentOrderDetails").Element("ProductsId").Value
           };

am able to get only product id 34 how can i get the another one too?Please help

<Order>
    <OrderID>123</OrderID>
    <PurchaseOrderNumber>12</PurchaseOrderNumber>
    <OrderPlacedDate>12/23/2012</OrderPlacedDate>
    <PurchasingContact>
     <FirstName>test</FirstName>
    </PurchasingContact>        
    <CurrentOrderDetails>
       <ProductsId>34</ProductsId>
       <OrderQuantity>2</OrderQuantity>
       <ProductsId>35</ProductsId>
       <OrderQuantity>2</OrderQuantity>
    </CurrentOrderDetails>
</Order>
<Order>
    .......
</Order>
  • 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-06-17T06:22:04+00:00Added an answer on June 17, 2026 at 6:22 am
     XDocument doc = XDocument.Load("Orders.xml");
     var data = from item in doc.Descendants("Order")
                select new
                {
                    OrderID = item.Element("OrderID").Value,
                    POnumber = item.Element("PurchaseOrderNumber").Value,
                    OrderDate = item.Element("OrderPlacedDate").Value,
                    PFirstName = item.Element("purchasingContact").Element("FirstName").Value,
                    Pids = item.Element("CurrentOrderDetails").Elements("ProductsId").Select(e => e.Value).ToList()
                };
    

    But to be honest – you should consider changing the XML structure. CurrentOrderDetails should look more like that:

    <CurrentOrderDetails>
        <Product id="34" quantity="2" />
        <Product id="35" quantity="2" />
    </CurrentOrderDetails>
    

    or

    <CurrentOrderDetails>
        <Product>
            <Id>34</Id>
            <Quantity>2</Quantity>
        </Product>
        <Product>
            <Id>35</Id>
            <Quantity>2</Quantity>
        </Product>
    </CurrentOrderDetails>
    

    This would make it easier to get product ID and it’s quantity together.

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

Sidebar

Related Questions

I am trying to read tags from XML using LibXML. I can print all
I am trying to read this XML file using PHP and I have two
I'm trying to read all the files in a folder. If the name is
I'm trying to read the content from a URL with Node.js but all I
I am trying to parse a XML document using Xerces, but I cant seem
I'm using kettle and trying to load both the attribute and node values from
I'm trying to read an xml file using xmlTextReader and store it in a
What I am not trying to do: Simply read XML in IE using jQuery.
I am trying to read this XML document with php. https://raw.github.com/yosoyadri/GeoNames-XML-Builder/master/continents-countries-statesprovinces.xml That is what
Alright guys, so Im using rapidXML to parse a very simple XML document. All

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.