2

XDocument中的 Elements是否有等效的XmlDocument节点定位器?

private const string InvalidDateTest = 
    "[text() = \"0000-00-00\" or text() = \"    -  -  \" or text() = \"-  -  \"]";

xmlDocument.SelectNodes("//DeterminedDate/Value" + InvalidDateTest);
4

3 回答 3

1

自己调味:

using System.Xml.XPath;

xDocument.XPathSelectElements("//DeterminedDate/Value" + InvalidDateTest);
于 2012-11-01T16:36:20.367 回答
0

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");
}
于 2012-11-01T16:09:22.007 回答
0

要区分节点,您需要简单地将扩展链接到后代调用,这将过滤掉所需的内容:

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
于 2012-11-01T16:23:28.407 回答