0

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");
ifti24
  • 191
  • 1
  • 5
  • 22
  • 2
    They are the [BOM](http://en.wikipedia.org/wiki/Byte_order_mark) for utf8. Answer: http://stackoverflow.com/a/4943344/815938 – kennyzx Oct 14 '14 at 03:42
  • possible duplicate of [XDocument: saving XML to file without BOM](http://stackoverflow.com/questions/4942825/xdocument-saving-xml-to-file-without-bom) – kennyzx Oct 14 '14 at 05:05

0 Answers0