XDocument中的 Elements是否有等效的XmlDocument节点定位器?
private const string InvalidDateTest =
"[text() = \"0000-00-00\" or text() = \" - - \" or text() = \"- - \"]";
xmlDocument.SelectNodes("//DeterminedDate/Value" + InvalidDateTest);
XDocument中的 Elements是否有等效的XmlDocument节点定位器?
private const string InvalidDateTest =
"[text() = \"0000-00-00\" or text() = \" - - \" or text() = \"- - \"]";
xmlDocument.SelectNodes("//DeterminedDate/Value" + InvalidDateTest);
自己调味:
using System.Xml.XPath;
xDocument.XPathSelectElements("//DeterminedDate/Value" + InvalidDateTest);
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");
}
要区分节点,您需要简单地将扩展链接到后代调用,这将过滤掉所需的内容:
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