我是WP7的新手。 我跟着this教程來讀寫一個xml文件,但是當我讀取xml文件時,它只顯示了我的xml文件的第一行。我不知道如何檢查天氣xml文件是否被程序正確編寫。 。WP7在IsolatedStorage中讀寫Xml
1.如何檢查保存在獨立存儲中的xml文件。
2.如何擺脫這個問題。
我的代碼編寫XML文件中的獨立存儲:
using (IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("mz1.xml", FileMode.Create, myIsolatedStorage))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("person");
writer.WriteElementString("node1", "value1");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
}
}
代碼讀取XML文件從獨立存儲:
using (IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoFileStream =
myIsolatedStorage.OpenFile("mz1.xml", FileMode.Open);
using (StreamReader reader = new StreamReader(isoFileStream))
{
textBlock1.Text= reader.ReadToEnd();
}
}
輸出:
<?xml version="1.0" encoding="utf-8"?>
日Thnx @alex爲reply.I安裝Explorer及其文檔中,它說添加引用IsolatedStorageExplorer組裝,但儘管我已經安裝了探險 – Mj1992 2012-03-24 12:44:38
大會沒有出現在我的視覺工作室@ Mj1992 - 當您打開添加引用對話框時,只需瀏覽到該庫所在的目錄並添加對.dll的引用 - 通常將其引導至安裝在C:\ Program Files \ WP7 Isolated Storage Explorer \ Library中 - hth – Alex 2012-03-24 12:49:37
thnx alot @Alex指出我完全忘了那個。 – Mj1992 2012-03-24 12:54:28