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.