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 }
WP7读取Xml文档 建议使用XmlReader