Create complete xml string using LINQ

Posted by Madhu.b.rokkam under LINQ category on | Points: 40 | Views : 2278
When ever there is a need to create an xml string with attributes and elements you can do this way

XElement xml = new XElement("Students",
new XElement("Madhu",
new XAttribute("YearOfBirth", 1990),
new XElement("Location", "Hyderabad")),
new XElement("Karthik",
new XAttribute("YearOfBirth", 1995),
new XElement("Location", "Chennai"))


This will result output as

<Madhu YearOfBirth="1990">
<Karthik YearOfBirth="1995">

Comments or Responses

Login to post response