Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting attribute value of an XML Document using C#

Tags:

c#

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".

like image 574
Shamim Hafiz - MSFT Avatar asked Sep 20 '10 10:09

Shamim Hafiz - MSFT


1 Answers

I would try something like this:

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

XmlElement root = doc.DocumentElement;

string s = root.Attributes["success"].Value;
like image 129
Edwin de Koning Avatar answered Sep 22 '22 15:09

Edwin de Koning