Windows Phone 7-加载大的xml文件 [英] windows phone 7 - loading a big xml file

查看:86
本文介绍了Windows Phone 7-加载大的xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将xml文件加载到我的应用程序并将其显示在ListBox上.问题在于该xml文件大约为5 MB,并且在手机上加载大约需要40秒.当手机锁定屏幕并返回时,又需要40秒钟.我试图使用isolatedstorage在其上存储数据,但是并没有提高性能.这是我加载数据的代码:

I am trying to load a xml file to my app and show it on a ListBox. The problem is that the xml file is about 5 MB, and it takes about 40 seconds on the phone to load. and when the phone locks the screen and returns back it takes another 40 seconds. I tried to use the isolatedstorage to store the data on it but it didn't improve performance. This is my code to load the data:

XDocument loadedData = XDocument.Load("BigFile.xml");
            var data = from query in loadedData.Descendants("w")
                       orderby (string)query.Element("e")
                       select new myClass
                       {
                           First = (string)query.Element("a"),
                           Second = (string)query.Element("e")
                       };
        ListBox.ItemsSource = data.ToList<myClass>();

反正有加快加载的速度吗?

Is there anyway to speed up the loading?

推荐答案

要提高性能,您可以执行以下操作:

To improve performance you can do the following:

  • 确保将负载移出ui线程
  • 将文件拆分成多个较小的文件,然后一次加载一个文件,并在添加每个文件时更新列表.
  • 如果可能,请重新格式化数据(在添加到应用程序之前),使其仅包含应用程序使用的绝对最小数据.
  • 将文件转换为可以更快解析的其他格式(尝试JSON).
  • (如果使用7.1)将数据放入数据库中,然后将其部署到XAP中.
  • 重新考虑是否需要大量数据.大/长列表很难在具有小屏幕的设备上浏览.

这篇关于Windows Phone 7-加载大的xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆