-2

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"?>
trailerman
  • 321
  • 5
  • 15
  • 1
    Without seeing your code how can we tell? – Charlieface Aug 28 '22 at 00:34
  • 2
    We need to see a [mcve] to help you, but if you are using `XmlDocument` then these may be relevant: [How to read processing instruction from an XML file using .NET 3.5](https://stackoverflow.com/q/3100345) and [How do I add a custom XmlDeclaration with XmlDocument/XmlDeclaration?](https://stackoverflow.com/q/334256). – dbc Aug 28 '22 at 01:03
  • You would have to give a [mcve], because we cannot repro your issue https://dotnetfiddle.net/djgyPV – Charlieface Aug 28 '22 at 04:07

1 Answers1

1

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");
}
Yitzhak Khabinsky
  • 18,471
  • 2
  • 15
  • 21