-4

Hi is there any way to download a DLL for XML so that i can use it in my project and how to read the XML file ? Say for example i want to read the first name's and last name's.

<?xml version="1.0"?>
<configuration>
  <appSettings>
     <add key="firstname" value="David"/>
     <add key="Lastname" value="Alan"/>
     <add key="Age" value="35"/>
     <add key="gender" value="male"/> 
     </appSettings> 
 </configuration>
jessica
  • 1,507
  • 3
  • 15
  • 18
  • 5
    What do you mean by "DLL for XML"? .NET already contains multiple XML APIs - I'd recommend looking into LINQ to XML. – Jon Skeet Jun 06 '13 at 17:22

1 Answers1

1

How about using Linq2Xml?

var xDoc = XDocument.Load(filename);
var dict = xDoc.Element("configuration").Element("appSettings")
            .Elements("add")
            .ToDictionary(e => e.Attribute("key").Value, e => e.Attribute("value").Value);

Console.WriteLine(dict["firstname"] + " " + dict["Lastname"]);

or you may want to use ConfigurationManager

var username = System.Configuration.ConfigurationManager.AppSettings["firstname"];
I4V
  • 34,891
  • 6
  • 67
  • 79