4
<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>

thanks in advance for your help. I have this xml database

i want to return all products that have the ListName = "out", but this query i´m trying it´s only returning the second product, and i need it to return the first and the second product.

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

thanks :)

1 Answer 1

6

Right now you just check the first Item element, instead you want to check if any Item's ListName matches "out":

var _queryItems = from c in xml.Descendants("Product") 
                  where c.Element("ItemLists")
                         .Elements("Item").Any( x=> x.Element("ListName").Value == "out") 
                  select c;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.