Home > Back-end >  XML Tag / Prolog Missing
XML Tag / Prolog Missing

Time:08-28

i am reading and serializing a xml file. I then make some changes to the serialized xml data and save again back to a new file. The serializing and deserializing, saving to file is all working, however I have a value at the top of the xml file that is missing.

How do I set this value before saving the xml file?

Original XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>

New File XML (missing )

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

CodePudding user response:

It is very simple to implement via LINQ to XML API.

c#

void Main()
{
    XDocument xdoc = XDocument.Parse("<root><el>123</el></root>"); // or .Load()
    xdoc.Declaration = new XDeclaration("1.0", "UTF-8", "false");
    xdoc.Save(@"e:\temp\Output.xml");
}
  • Related