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

  • Home
  • SEARCH
  • 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 7738193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:12:06+00:00 2026-06-01T08:12:06+00:00

in my ASP.Net C# application, I am trying to read a nested XML Elements

  • 0

in my ASP.Net C# application,

I am trying to read a nested XML Elements to an Anonymous type collections.

here is the XML sample

    <MedicationDispensed xmlns="http://www.ncpdp.org/schema/SCRIPT">
  <DrugDescription>OXYCODONE W/APAP 5/325 TAB</DrugDescription>
  <DrugCoded>
    <ProductCode>00406051205</ProductCode>
    <ProductCodeQualifier>ND</ProductCodeQualifier>
  </DrugCoded>
  <Quantity>
    <Qualifier>00</Qualifier>
    <Value>60.0</Value>
    <CodeListQualifier>87</CodeListQualifier>
  </Quantity>
  <DaysSupply>15</DaysSupply>
  <LastFillDate>2012-04-03</LastFillDate>
  <Pharmacy>
    <Identification>
      <NCPDPID>1234567</NCPDPID>
    </Identification>
    <StoreName>WALGREENS #00000</StoreName>
    <Address>
      <AddressLine1>1 CENTRAL STREET</AddressLine1>
      <City>INDIANAPOLIS</City>
      <State>IN</State>
      <ZipCode>46201</ZipCode>
    </Address>
    <PhoneNumbers>
      <Phone>
        <Number>8005551212</Number>
        <Qualifier>TE</Qualifier>
      </Phone>
    </PhoneNumbers>
  </Pharmacy>
  <Prescriber>
    <Identification>
      <DEANumber>KR4184999</DEANumber>
    </Identification>
    <Name>
      <LastName>SMITH</LastName>
      <FirstName>JOHN</FirstName>
      <MiddleName>E</MiddleName>
    </Name>
    <Address>
      <AddressLine1>MERCY CLINIC</AddressLine1>
      <City>ST. PAUL</City>
      <State>MN</State>
      <ZipCode>55101</ZipCode>
    </Address>
  </Prescriber>
</MedicationDispensed>

I am successful till here

 var MedicationDispensed = (from elem in xdoc.Descendants(NameSpace + "MedicationDispensed")
                                           .Descendants(NameSpace + "DrugCoded")
                                           //.Descendants(NameSpace + "Quantity")
                                       select new
                                       {
                                           DrugDescription = elem.Parent.Element(NameSpace + "DrugDescription").Value,
                                           ProductCode = elem.Element(NameSpace + "ProductCode").Value,
                                           ProductCodeQualifier = elem.Element(NameSpace + "ProductCodeQualifier").Value,
                                           //Qualifier = elem.Parent.Element(NameSpace + "Qualifier").Value,
                                           //Value = elem.Element(NameSpace + "Value").Value,
                                           //CodeListQualifier = elem.Element(NameSpace + "CodeListQualifier").Value,
                                           DaysSupply = elem.Parent.Element(NameSpace + "DaysSupply").Value,
                                           LastFillDate = elem.Parent.Element(NameSpace + "LastFillDate").Value
                                       }).ToList();

I am not able to query for Quantity and further i have to do for Pharmacy and Prescriber.
Any help would greatly be appreciated.

  • 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-01T08:12:07+00:00Added an answer on June 1, 2026 at 8:12 am

    Well I got my answer with the help of another post in StackOverflow

    Here is my code to achieve what i want.

     var MedicationDispensed = (from MD in xdoc.Descendants(NameSpace + "MedicationDispensed")
                                           let DrugCoded = MD.Element(NameSpace + "DrugCoded")
                                           let Quantity = MD.Element(NameSpace + "Quantity")
                                           let Pharmacy = MD.Element(NameSpace + "Pharmacy")
                                           let phIdentification = Pharmacy.Element(NameSpace + "Identification")
                                           let phAddress = Pharmacy.Element(NameSpace + "Address")
                                           let phPhoneNumbers = Pharmacy.Element(NameSpace + "PhoneNumbers")
                                           let phPhone = phPhoneNumbers.Element(NameSpace + "Phone")
                                           let Prescriber = MD.Element(NameSpace + "Prescriber")
                                           let prIdentification = Prescriber.Element(NameSpace + "Identification")
                                           let prName = Prescriber.Element(NameSpace + "Name")
                                           let prAddress = Prescriber.Element(NameSpace + "Address")
                                           select new
                                           {
                                               DrugDescription = MD.Element(NameSpace + "DrugDescription").Value,
                                               ProductCode = DrugCoded.Element(NameSpace + "ProductCode").Value,
                                               ProductCodeQualifier = DrugCoded.Element(NameSpace + "ProductCodeQualifier").Value,
                                               Qualifier = Quantity.Element(NameSpace + "Qualifier").Value,
                                               Value = Quantity.Element(NameSpace + "Value").Value,
                                               CodeListQualifier = Quantity.Element(NameSpace + "CodeListQualifier").Value,
                                               DaysSupply = MD.Element(NameSpace + "DaysSupply").Value,
                                               LastFillDate = MD.Element(NameSpace + "LastFillDate").Value,
                                               phStoreName = Pharmacy.Element(NameSpace + "StoreName").Value,
                                               phNCPDPID = phIdentification.Element(NameSpace + "NCPDPID").Value,
                                               phAddress1 = phAddress.Element(NameSpace + "AddressLine1").Value,
                                               phCity = phAddress.Element(NameSpace + "City").Value,
                                               phState = phAddress.Element(NameSpace + "State").Value,
                                               phZipcode = phAddress.Element(NameSpace + "ZipCode").Value,
                                               phPhoneNumber = phPhone.Element(NameSpace + "Number").Value,
                                               phQualifier = phPhone.Element(NameSpace + "Qualifier").Value,
                                               prDEANumber = prIdentification.Element(NameSpace + "DEANumber").Value,
                                               prLastName = prName.Element(NameSpace + "LastName").Value,
                                               prFirstName = prName.Element(NameSpace + "FirstName").Value,
                                               prMiddleName = prName.Element(NameSpace + "MiddleName").Value,
                                               prAddress1 = prAddress.Element(NameSpace + "AddressLine1").Value,
                                               prCity = prAddress.Element(NameSpace + "City").Value,
                                               prState = prAddress.Element(NameSpace + "State").Value,
                                               prZipCode = prAddress.Element(NameSpace + "ZipCode").Value
                                           }).ToList();
    

    Hope this will be useful for someone who is in need of same work.

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

Sidebar

Related Questions

My clients are trying to revive an ASP.NET 1.0 application (yes, you read that
Long story short, I have an ASP.NET application I'm trying to debug and at
I am trying to host an ASP.NET application that is running the Silverlight Video
We've got an Asp.Net web application we're trying to get pseudo-deployed to a folder,
I have this code in my ASP.NET application written in C# that is trying
What I'm trying to achieve: Intercept requests for .asp files using an asp.net application
I'm having a really frustrating error trying to secure an ASP.NET application using the
trying to render the contents of an IFrame in an Asp.Net Application. This is
I'm trying to fetch some settings from my membership provider in my asp.net application
I'm trying to write an ASP.NET MVC application where user privilege is based upon

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.