[英]looping through same multiple nodes in an xml and merging numbers that are strings
[英]Looping through XML nodes
我試圖遍歷節點並檢查InnerText以確定它們是否包含關鍵字。 我曾在WPF中工作過,但是我對使用UWP並不陌生,這讓我頭疼。 任何建議,將不勝感激。
我目前只在這里得到:0,所以我知道它開始了foreach循環。 應該顯示大約100個節點。
在WPF中,我使用了它,效果很好:
foreach (XmlNode node in nodeList)
在不起作用的UWP中嘗試這樣做:
foreach (IXmlNode node in nodeList)
這是我遇到麻煩的部分代碼:
var doc = new XmlDocument();
StorageFile tempFile = await ApplicationData.Current.LocalFolder.GetFileAsync("weatheralerts.xml");
String datas = await FileIO.ReadTextAsync(tempFile);
doc.LoadXml(datas);
var nodeList = doc.SelectNodesNS("/ns:feed/ns:entry", "xmlns:ns='http://www.w3.org/2005/Atom'");
var x = 0;
foreach (IXmlNode node in nodeList)
{
Data1.Text = "HERE: " + x;
x++;
}
如果使用System.Xml.XmlDocument
而不是Windows.Data.Xml.Dom.XmlDocument
,則應該可以將SelectNodes
方法與XmlNamespaceManager
:
var doc = new XmlDocument();
StorageFile tempFile = await ApplicationData.Current.LocalFolder.GetFileAsync("weatheralerts.xml");
String datas = await FileIO.ReadTextAsync(tempFile);
doc.LoadXml(datas);
var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("ns", "http://www.w3.org/2005/Atom");
var nodeList = doc.SelectNodes("/ns:feed/ns:entry", nsmgr);
var x = 0;
foreach (XmlNode node in nodeList)
{
Data1.Text = "HERE: " + x;
x++;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.