I'm trying to load XML without root element. I want to use LINQ to XML.
Following answer: https://stackoverflow.com/a/18186317/16514891 i recreated this code:
var doc = File.ReadAllText(Path.Combine(Settings.GameFolderPath, path));
var rootedDoc = "<root>" + doc + "</root>";
XDocument correctDoc = XDocument.Parse(rootedDoc);
But i get XMLException "Unexpected XML declaration" on XDocument.Parse()
, Line 1, Position 9. Using File.WriteAllText(path, rootedDoc)
i know that first line looks like expected: <root><?xml version="1.0" encoding="utf-16"?>
. It had to work somehow in answer i linked, but i don't understand how, how do you keep declaration first after wrapping original file?