我在线有一个XML文档,我试图获取并显示标签中特定节点的值。
XML:
<h1 class="contents-header">Upper Limit Management</h1>
<div class="contents-body">
<table class="data-table" width="500px">
<tr>
<th scope="col" width="165px">Max. Allowance Set</th>
<th scope="col" width="165px">Max. Allowance</th>
<th scope="col" width="170px">Meter Count</th>
</tr>
<tr>
<td>Disable</td>
<td>0</td>
<td>32</td>
</tr>
</table>
</div>
<hr class="contents-end" title="">
</div>
这是我尝试获取并显示它的C#代码。我试图显示节点&#34; Meter Count&#34;它的值为32。
private void loadxmlbtn_Click(object sender, EventArgs e)
{
string myXmlString = new WebClient().DownloadString("http://10.86.192.24/system.xml");
XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString);
XmlNodeList xnList = xml.SelectNodes("/Upper Limit Management/Meter Count");
foreach (XmlNode xn in xnList)
{
string count = xn["td"].InnerText;
countlbl.Text = "Your current count is: " + count;
}
}
但是,点击按钮时,没有任何事情发生。是否有人能够指出可能出现的问题?