gpt4 book ai didi

c# - 使用 C# 获取 XML 文档的属性值

转载 作者:可可西里 更新时间:2023-11-01 08:51:11 25 4
gpt4 key购买 nike

假设我有以下 XML 文档。

<reply success="true">More nodes go here</reply>

如何获取属性 success 的值,在本例中为字符串“true”。

最佳答案

我会尝试这样的事情:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<reply success=\"true\">More nodes go here</reply>");

XmlElement root = doc.DocumentElement;

string s = root.Attributes["success"].Value;

关于c# - 使用 C# 获取 XML 文档的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3750678/

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