Otto
Otto

Reputation: 4200

How do I get the node name in XML with C#?

I want to get the node by his name and not by his item id, at the moment i have this:

XmlNode xmlNodoDebug = docWebConfig.DocumentElement.SelectSingleNode("system.web/compilation");
Response.Write(xmlNodoDebug.Attributes.Item(1).Value); // returns value "true"

My XML is the Web.Config of other C# projects:

<compilation defaultLanguage="c#" debug="true" />

I want to get the value of that node by his name, "debug".

Upvotes: 1

Views: 486

Answers (2)

bobbymcr
bobbymcr

Reputation: 24177

Yes, just use the indexer which accepts a string index: http://msdn.microsoft.com/en-us/library/1b823yx9.aspx

XmlAttribute attribute = xmlNodoDebug.Attributes["debug"];

Upvotes: 1

harryovers
harryovers

Reputation: 3138

try this:

xmlNodoDebug.Attributes["debug"].Value;

Upvotes: 1

Related Questions