使用 C# 获取 XML 文档的属性值 [英] Getting attribute value of an XML Document using C#

查看:34
本文介绍了使用 C# 获取 XML 文档的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下 XML 文档.

Suppose I have the following XML Document.

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

如何获取属性 success 的值,在本例中为字符串true".

How to get the value of the attribute success, which in this case would be the string "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# 获取 XML 文档的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆