XmlException在C#Windows Phone 7上未处理

时间:2012-12-10 19:53:02

标签: c# xml xml-parsing windows-phone-7.1 linq-to-xml

我正在尝试打开一个XML文件,当我编译我的应用程序并且遇到一些问题时,该文件被复制为IsolatedStorage的内容;

  

根级别的数据无效。第1行,第411位。

我不完全确定这意味着什么,并且访问我的本地搜索引擎只会增加我的困惑,任何人都可以告诉我,如果我做了什么严重错误或者我的数据结构是否糟糕请

这是我的函数,它从文件加载数据并将其解析为变量:

private void ReadData()
{
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    {
        if (store.FileExists("appdata.xml"))
        {
            IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("appdata.xml", FileMode.Open, store);
            XDocument document;
            using (XmlReader reader = XmlReader.Create(fileStream))
            {
                if (reader != null)
                {
                    document = XDocument.Load(reader); // <-- Error occurs here
                    ListBox listBox = new ListBox();

                    var data = from query in document.Descendants("myData")
                               select new DataHolder
                               {
                                   CashData = (string)query.Element("CashData"),
                                   LandGoData = (string)query.Element("LandGoData"),
                                   FreeParkingData = (string)query.Element("FreeParkData"),
                                   CircuitData = (string)query.Element("FullCircuitData"),
                                   AuctionData = (string)query.Element("AuctionData")
                               };
                    listBox.ItemsSource = data;

                    StartCashRule.Text = (string)listBox.FindName("myData");
                }
            }
            fileStream.Close();
        }
    }            
}

这是我的xml文档:

<?xml version="1.0" encoding="utf-8" ?>
<RootPath>
    <CashData>Value1</CashData>
    <LandGoData>Value2</LandGoData>
    <FreeParkData>Value3</FreeParkData>
    <FullCircuitData>Value4</FullCircuitData>
    <AuctionData>Value5</AuctionData>
</RootPath>

0 个答案:

没有答案