Wednesday, 11 December 2019

C# - Create an XML Document with LINQ to XML

using System.Xml.Linq;


XDocument ackDoc = new XDocument(new XDeclaration("1.0", "utf - 8", "true"),
    new XElement("DepartmentsDetails"
    , new XElement("Department","Technical")
    , new XElement("Department", "Finanace")
    , new XElement("Department", "Human Resource Management")
    , new XElement("Department", "Facilities")
    , new XElement("Department", "Research and Development"));

ackDoc.Save(xmlFilePath);

Output

<DepartmentsDetails>
    <Department>Technical</Department>
    <Department>Finanace</Department>
    <Department>Human Resource Management</Department>
    <Department>Facilities</Department>
    <Department>Research and Development</Department>
</DepartmentsDetails>

No comments: