gpt4 book ai didi

c# - XPath C# 属性值

转载 作者:行者123 更新时间:2023-12-03 17:17:33 30 4
gpt4 key购买 nike

以下是读入XmlDocument的XML文件

<Test xmlns="http://api.test.com/v2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result id="2015" description="Invalid Token" />
</Test >

我需要的是存储在一些 TextBox 中的 'id' 属性值(“2015”)

这就是 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.

}

最佳答案

var id = Test.FirstChild.Attributes["id"].Value;

关于c# - XPath C# 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11955966/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com