以下是( “2015”)存储在某个文本框的XPath C#属性值
读入的XmlDocument
<Test xmlns="http://api.test.com/v2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result id="2015" description="Invalid Token" />
</Test >
我需要的是 'id' 属性值的XML文件,这是多么的XmlDocument被加载
XmlDocument updateUser = new XmlDocument();
updateUser.Load(response.GetResponseStream());
很好地工作到这里。
然后,创建命名空间和搜索节点
XmlNamespaceManager nsmgr = new XmlNamespaceManager(updateUser.NameTable);
nsmgr.AddNamespace("restup", "http://api.test.com/v2");
XmlNodeList locationElements1 = updateUser.SelectNodes("//restup:Test", nsmgr);
foreach (XmlNode Test in locationElements1)
{
//What DO I do here to get the value of 'id' attribute from the 'Result' node and save it in txtTest Textbox.
}
哦,你发布的XML有用的另一种方法。我会改变我的答案... – 2012-08-14 15:50:22