2011-10-06 91 views
3
<InventoryList> 
<Product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <Id>1</Id> 
    <Name>Pizza Ristorante Hawaii</Name> 
    <Price>2.99</Price> 
    <VariableWeightPrice>€ 8,42/kg</VariableWeightPrice> 
    <Brand>Dr.Oetker</Brand> 
    <PackageInfo>355 GR</PackageInfo> 
    <categoryString /> 
    <PictureSmallFilename>1small.jpg</PictureSmallFilename> 
    <InformationTakenFrom>Jumbo</InformationTakenFrom> 
    <MarketItemUrl></MarketItemUrl> 
    <BarCode>4001724819608</BarCode> 
    <IsBlackListed>false</IsBlackListed> 
    <ItemLists> 
    <Item> 
     <ListName>in</ListName> 
     <Quantity>1</Quantity> 
     <QuantityWeight>0</QuantityWeight> 
    </Item> 
    <Item> 
     <ListName>out</ListName> 
     <Quantity>2</Quantity> 
     <QuantityWeight>0</QuantityWeight> 
    </Item> 
    </ItemLists> 
</Product> 
<Product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <Id>2</Id> 
    <Name>Produto 2</Name> 
    <Price>2.99</Price> 
    <VariableWeightPrice>€ 5,55/kg</VariableWeightPrice> 
    <Brand>Dr.Oetker</Brand> 
    <PackageInfo>355 GR</PackageInfo> 
    <categoryString /> 
    <PictureSmallFilename>1small.jpg</PictureSmallFilename> 
    <InformationTakenFrom>Jumbo</InformationTakenFrom> 
    <MarketItemUrl></MarketItemUrl> 
    <BarCode>4001724819608</BarCode> 
    <IsBlackListed>false</IsBlackListed> 
    <ItemLists> 
    <Item> 
     <ListName>out</ListName> 
     <Quantity>1</Quantity> 
     <QuantityWeight>0</QuantityWeight> 
    </Item> 
    </ItemLists> 
</Product> 
</InventoryList> 

在此先感謝您的幫助。 我有這個XML數據庫Linq到Xml查詢到子節點

我想返回所有產品有ListName =「出」,但這個查詢我試圖它只返回第二個產品,我需要它返回第一個和第二個產品。

var _queryItems = from c in xml.Descendants("Product") 
          where 
           c.Element("ItemLists").Element("Item").Element("ListName").Value == "out" 
          select c; 

謝謝:)

回答

4

現在你只需要檢查的第一Item元素,而是要檢查是否任何項目的ListName比賽「走出去」:

var _queryItems = from c in xml.Descendants("Product") 
        where c.Element("ItemLists") 
         .Elements("Item").Any(x=> x.Element("ListName").Value == "out") 
        select c; 
+0

非常感謝你 – ArdethLostris