C# xdocumentxpath+;正则表达式元素定位器

C# xdocumentxpath+;正则表达式元素定位器,c#,xml,linq-to-xml,C#,Xml,Linq To Xml,中的元素是否有等效的节点定位器 XDocument+Xpath示例: using(var stream = new StringReader(xml)) { XDocument xmlFile = XDocument.Load(stream); var query = (IEnumerable) xmlFile.XPathEvaluate("/REETA/AFFIDAVIT/COUNTY_NAME"); foreach(var band in query.Cast <

中的元素是否有等效的节点定位器


XDocument+Xpath示例:

using(var stream = new StringReader(xml))
{
    XDocument xmlFile = XDocument.Load(stream);
    var query = (IEnumerable) xmlFile.XPathEvaluate("/REETA/AFFIDAVIT/COUNTY_NAME");
    foreach(var band in query.Cast < XElement > ())
    {
        Console.WriteLine(band.Value);
    }
    xmlFile.Save("books.xml");
}
使用(var stream=newstringreader(xml))
{
XDocument xmlFile=XDocument.Load(流);
var query=(IEnumerable)xmlFile.xpatheevalue(“/REETA/affidation/country_NAME”);
foreach(query.Cast()中的变量带)
{
控制台写入线(带值);
}
Save(“books.xml”);
}

要区分节点,只需将扩展链接到子代调用即可过滤出所需内容:

string Data = @"<?xml version=""1.0""?>
<Notifications>
   <Alerts>
      <Alert>1</Alert>
      <Alert>2</Alert>
      <Alert>3</Alert>
   </Alerts>
</Notifications>";


XDocument.Parse(Data)
         .Descendants("Alert")
         .Where (node => int.Parse(node.Value) > 1 && int.Parse(node.Value) < 3)
         .ToList()
         .ForEach(al => Console.WriteLine ( al.Value ) );       // 2 is the result
字符串数据=@”
1.
2.
3.
";
XDocument.Parse(数据)
.后代(“警报”)
.Where(node=>int.Parse(node.Value)>1&&int.Parse(node.Value)<3)
托利斯先生()
.ForEach(al=>Console.WriteLine(al.Value));//结果是什么
我自己做的:

using System.Xml.XPath;

xDocument.XPathSelectElements("//DeterminedDate/Value" + InvalidDateTest);
using System.Xml.XPath;

xDocument.XPathSelectElements("//DeterminedDate/Value" + InvalidDateTest);