Search code examples
c#.netxmlvisual-studio-2010xmldocument

select all xml child nodes that start with a string


I am using C# .

I have an xml node with child nodes as follows :

<PriceID>32</PriceID>
<Store_1> 344</Store_1>
      <Store_32> 343 </Store_32>

I would like to select all nodes that start with Store

Is there a way I can do it ?

I know there is a way to select nodes with specific names ..

  XmlNodeList xnList = quote.SelectNodes("Store_1");

Does anyone know what will help me ?


Solution

  • You can use Linq2Xml

    var xDoc = XDocument.Parse(xmlstring);
    var stores = xDoc.Descendants()
                .Where(d => d.Name.LocalName.StartsWith("Store"))
                .ToList();