metro 下载xml文件

public class downClass1
{
public IStorageFile pResultStorageFile;
public async Task<IStorageFile> down()
{
string CountriesFile = "fruit.xml";
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await InstallationFolder.CreateFileAsync(CountriesFile);//下载到本地
BackgroundDownloader ppp = new BackgroundDownloader();
DownloadOperation pDownloadOperation = ppp.CreateDownload(new Uri("https://files.cnblogs.com/gisbeginner/fruit.xml"), file);
await pDownloadOperation.StartAsync();
pResultStorageFile = pDownloadOperation.ResultFile;
return pResultStorageFile;
}
}

获得一个pResultStorageFile 文件引用

downClass1 pdownClass1 = new downClass1();
pDownLoadFile = pdownClass1.down() ;
pDownLoadFile1 = await pDownLoadFile;

 //获得流

Stream Countries = await pDownLoadFile1.OpenStreamForReadAsync();

//利用流 解析xml 

XDocument xDOC = XDocument.Load(Countries);
var query = from a in xDOC.Elements("kinds").Elements("kind").Elements(transferValue)
select a.Value;
foreach (var C in query)
{
string CC = C;
}
itemListView.ItemsSource = query;

posted on 2012-09-17 17:41  GIS-MAN  阅读(217)  评论(0编辑  收藏  举报

导航