I'm using the below code to generate an xml file. The xml file is generating successfully. But the problem is - at the beginning of the file I'm getting some special characters. And for this reason the xml validation failed.
Special Characters at the beginning of the xml file :-
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
XML File Generation Code :-
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("This is a comment"),
new XElement("Persons",
new XElement("Person", new XAttribute("name", "John Smith"),
new XElement("Age", new XText("30")),
new XElement("Gender", new XText("Male"))),
new XElement("Person", new XAttribute("name", "Mike Folley"),
new XElement("Age", new XText("25")),
new XElement("Gender", new XText("Male")))));
doc.Save(@"C:\sample2.xml");