我有一个想要更新的现有 xml 文件。
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);
}
}
问题是每当我使用file.Save(ISFS)
,然后尝试再次加载它,使用相同的方法,就会报错
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.
更新 :
这是保存后的文件
<?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>