Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用LINQtoXMLASP.NETC查询嵌套的XML元素#_Xml_Asp.net Mvc 3_C# 4.0_Linq To Xml - Fatal编程技术网

使用LINQtoXMLASP.NETC查询嵌套的XML元素#

使用LINQtoXMLASP.NETC查询嵌套的XML元素#,xml,asp.net-mvc-3,c#-4.0,linq-to-xml,Xml,Asp.net Mvc 3,C# 4.0,Linq To Xml,在我的ASP.Net C#应用程序中 我正在尝试将嵌套的XML元素读取到匿名类型集合 下面是XML示例 <MedicationDispensed xmlns="http://www.ncpdp.org/schema/SCRIPT"> <DrugDescription>OXYCODONE W/APAP 5/325 TAB</DrugDescription> <DrugCoded> <ProductCode>0040

在我的ASP.Net C#应用程序中

我正在尝试将嵌套的XML元素读取到匿名类型集合

下面是XML示例

    <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>
我无法查询数量,我还必须为药房和处方医生查询。
任何帮助都将不胜感激。

嗯,我是在另一篇文章的帮助下得到答案的

这是我的代码来实现我想要的

 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();
希望这将是有用的人谁是需要同样的工作

 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();