onsdag den 15. juni 2016

Loading XML values in C#

XMLFile: RESTORE.XML
<EmployeeDetails>
  <EmployeeID>156824</EmployeeID>
  <EmployeeName>ALEX</EmployeeName>
  <EmployeeAge>29</EmployeeAge>
</EmployeeDetails>

C#
using System.Xml.Linq;
XDocument xdoc = XDocument.Load("RESTORE.XML");
xdoc.Descendants("EmployeeID").First().Value;
xdoc.Descendants("EmployeeName").First().Value;

If you make the XML file in visual studio, then click on it's properties, and chose "copy". Then it will copy the xml to the Debug/Release directory too