[英]XPath in C# code behind of WPF
如果您在XAML中綁定XML文檔,則可以使用XPath,但如果您在后面的代碼中動態加載XML文檔會怎么樣? C#代碼背后是否有可用的XPath方法?
(使用.NET 3.5 SP1)
將XML加載到代碼后面的XPathDocument中,並使用XPathNavigator來保存查詢。 XPathNavigator.Select()的結果是一個返回所選節點的迭代器。
示例(使用System.XML和System.Xml.XPath):
XPathDocument doc = new XPathDocument(@"c:\filepath\doc.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator iter = nav.Select("/xpath/query/here");
while(iter->MoveNext)
{
//Do something with node here.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.