首页 新闻 会员 周边

请教windowsPhone开发:xdocument 加载stream时报错。

0
悬赏园豆:15 [已解决问题] 解决于 2011-07-22 18:34

windowsPhone mango beta2

第一次运行会将创建xml文件,并且在第二次运行调试时,可以跟踪到xml的内容为

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
< root>
  <Date-2011-07-20-10-19-18 day="1" CourseTime="c8_10">中关村</Date-2011-07-20-10-19-18>
< /root>

,当走到XDocument xdoc = XDocument.Load(isoStream),就开始报错”Root element is missing"

请教 。谢谢

  
1 源代码:
2
3
4 if (MessageBox.Show("确定要对本次上课签字吗?", "签字", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
5 {
6 string eleName = "Date-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss");
7 XElement xEle = new XElement(eleName);
8 xEle.Value = XControls.XTextBox.CurrTextBox.Text;
9
10 XAttribute xA1 = new XAttribute("day", 1);
11 XAttribute xA2 = new XAttribute("CourseTime", XControls.XTextBox.CurrTextBox.Name);
12 xEle.Add(xA1, xA2);
13 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
14 {
15 if (!isoFile.FileExists(FILENAME))
16 {
17 isExists = false;
18 using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(FILENAME, FileMode.Create, isoFile))
19 {
20 XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("root", xEle));
21 //StreamWriter sw = new StreamWriter(isoStream);
22 xdoc.Save(isoStream);
23 //sw.Close();
24 //sw.Dispose();
25 }
26 }
27 else
28 {
29 using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(FILENAME, FileMode.Open, FileAccess.ReadWrite, isoFile))
30 {
31 //StreamReader sr = new StreamReader(isoStream);
32 //Debug.WriteLine(sr.ReadToEnd());
33 //XDocument xdoc = XDocument.Parse(sr.ReadToEnd());
34 //xdoc
35 XDocument xdoc = XDocument.Load(isoStream);
36 XElement rootEle = xdoc.Root;
37 Debug.WriteLine(xdoc.Root);
38 rootEle.Add(xEle);
39 //StreamWriter sw = new StreamWriter(isoStream);
40 xdoc.Save(isoStream);
41 //sw.Close();
42 //sw.Dispose();
43 //sr.Close();
44 //sr.Dispose();
45 }
46 }
47 }
48 MessageBox.Show("签字已成功!");
49 }
残剑的主页 残剑 | 初学一级 | 园豆:185
提问于:2011-07-20 15:20
< >
分享
最佳答案
0

WP7读取Xml文档  建议使用XmlReader

收获园豆:15
Devil_jim | 菜鸟二级 |园豆:220 | 2011-07-22 17:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册