我是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