简体   繁体   English

选择所有以字符串开头的xml子节点

[英]select all xml child nodes that start with a string

I am using C# . 我正在使用C#。

I have an xml node with child nodes as follows : 我有一个带有子节点的xml节点,如下所示:

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

I would like to select all nodes that start with Store 我想选择所有以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 ? 有谁知道对我有帮助吗?

You can use Linq2Xml 您可以使用Linq2Xml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM