以下是( 「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