开发者

select Entity using Linq to xml

开发者 https://www.devze.com 2023-03-19 21:52 出处:网络
i\'m new to linq , iv\'e got an xml file as such <?xml version=\"1.0\" standalone=\"yes\"?> <NewDataSet>

i'm new to linq , iv'e got an xml file as such

  <?xml version="1.0" standalone="yes"?>
   <NewDataSet>
      <Order>
          <OrderID>开发者_开发知识库;1</OrderID>
          <ProductID>11</ProductID>
          <UnitPrice>14.0000</UnitPrice>
          <Quantity>12</Quantity>
          <Discount>0</Discount>
      </Order>
      <Order>
          <OrderID>2</OrderID>
          <ProductID>42</ProductID>
          <UnitPrice>9.8000</UnitPrice>
          <Quantity>10</Quantity>
          <Discount>0</Discount>
      </Order>
      .
      .
 </NewDataSet>

now i'm trying to query all the elements named "Order"

        var query = from e in XElement.Load("..//..//OrderDetailsData.xml").Elements("Order")
                    select e.Element("Order"); 

this returns nothing

iv'e also tried

        var query = from e in XElement.Load("..//..//OrderDetailsData.xml").Descendants("NewDataSet").Elements("Order")
        select e.Element("Order");

the question is how do i select multiple elements named Order ? (not that this selects even a single element) is there spouse to be some kind of lambada "where e => e " or something of the sort ...

to conclude .. i just don't understand how to query using linq to xml as i would linq a list


You simply want var query = XElement.Load("..//..//OrderDetailsData.xml").Elements("Order"); or if you really think that a from select is helpful then use var query = from order in XElement.Load("..//..//OrderDetailsData.xml").Elements("Order") select order;.

0

精彩评论

暂无评论...
验证码 换一张
取 消