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

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

问题描述

假设我有下面的XML文档。

Suppose I have the following XML Document.

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

如何获得属性的成功,在这种情况下将是字符串真的值。

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天全站免登陆