简体   繁体   中英

XML header gets deleted when loading in XDocument

I have an XML document which I load in visual studio like this:

using (MemoryStream stream = new MemoryStream(xmlFile.Content))
{
    using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream))
    {
        var xmlDocument = XDocument.Load(xmlReader, LoadOptions.None);
    }
}

My only issue is that from the XML file the header gets deleted as soon as it gets loaded.

The header:

<?xml version="1.0" encoding="utf-8"?>

I tried all the load options but it didn't work. Is there a fix for this problem?

Fildor Thanks you! I just add the declaration again after Iam done with the file.

Danke und LG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM