I have an existing xml file which I want to update.
using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
{
// Load the xml document for reading
using (IsolatedStorageFileStream ISFS = ISF.OpenFile(FILE_NAME, FileMode.Open, FileAccess.ReadWrite))
{
XDocument file= XDocument.Load(ISFS);
//Edit the file
file.Save(ISFS);
}
}
The problem is whenever I use file.Save(ISFS)
, and then try to load it again, using same method, an error is reported
System.Xml.XmlException was unhandled by user code
HResult=-2146232000
Message=Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 25, position 14.
UPDATE :
Here's the file after saving
<?xml version="1.0" encoding="utf-8"?>
<A>
<AB ID="0">
<NickName>Dummy</NickName>
</AB>
</A><?xml version="1.0" encoding="utf-8"?>
<A>
<AB ID="0">
<NickName>Dummy</NickName>
</AB>
<AB ID="1">
<NickName>My1</NickName>
</AB>
</A>