I have a XML document called RESTORE.XML It hold these values..
<EmployeeDetails>
<EmployeeID>156824</EmployeeID>
<EmployeeName>ALEX</EmployeeName>
<EmployeeAge>29</EmployeeAge>
</EmployeeDetails>
From my c# application i want to read these three values and store it in 3 different variables.
How can do it using c# ? Thanks.
This should work:
using System.Xml.Linq;
XDocument xdoc = XDocument.Load("RESTORE.XML");
xdoc.Descendants("EmployeeID").First().Value;
xdoc.Descendants("EmployeeName").First().Value;
try this:
XElement xml = XElement.Parse(@"
<EmployeeDetails>
<EmployeeID>156824</EmployeeID>
<EmployeeName>ALEX</EmployeeName>
<EmployeeAge>29</EmployeeAge>
</EmployeeDetails>");
int EmployeeID = int.Parse(xml.Element("EmployeeID").Value);
string EmployeeName = xml.Element("EmployeeName").Value;
int EmployeeAge = int.Parse(xml.Element("EmployeeAge").Value);
but replace the parse with a load of your xml file instead...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With