I want to know how to get attribute \"text\" via c#?
Example xml:
You could use XDocument
and LINQ
You'll need to include the System.Xml.Linq.XDocument
namespace.
Then you could do something like:
XDocument document = XDocument.Load(filePath);
var modes = (from modes in document.Root.Descendants("Mode")
select modes.Attribute("Name").Value).ToList();
Like this:
const string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Model Name=""modelname"">
<Mode Name=""text"">
<Class>Class1</Class>
</Mode>
</Model>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Console.WriteLine(doc.DocumentElement["Mode"].Attributes["Name"].Value);