Windows 8 学习笔记(十四)--.map文件与.kml文件的解析


 

这段时间在做一个通过从网络上抓取的.map文件及区域图片,进行相应的加载定位,并将导航路径输出为.KML格式,以便下次加载显示上次路径。用过Google Earth的应该知道这两种文件格式。
.map文件解析
该文件不是XML文件格式,但却有固有的输出顺序,我只需按固定的顺序截取我要的信息即可,当然我这里有的最笨的方法,字符行的形式进行截取的,这个方法通用性太低,但我实在不知用哪种方式,若有知晓的,还忘告知~
复制代码
FileOpenPicker filepicker =  new FileOpenPicker();
                filepicker.FileTypeFilter.Add( " .map ");
                filepicker.ViewMode = PickerViewMode.Thumbnail;
                StorageFile file = await filepicker.PickSingleFileAsync();
                 if ( null != file)
                {
                    IList< string> fileContent = await FileIO.ReadLinesAsync(file);
            。。。 
复制代码

}

 

.kml文件解析
kml文件是XML文件格式,但有细微的区别,它有头文件
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">

这样的格式C#中不能成功加载文件,我中间多走了一步去中转了下,将xmlns:kml格式先替换为正常的XML文件格式,等读取完成后再将其写回文件中去。 

.kml文件的读取 

 View Code

 
复制代码
FileOpenPicker filepicker =  new FileOpenPicker();
                filepicker.FileTypeFilter.Add( " .kml ");
                filepicker.ViewMode = PickerViewMode.Thumbnail;
                StorageFile file = await filepicker.PickSingleFileAsync();
                 // kml文件转义
                 string fileContent = await FileIO.ReadTextAsync(file);
                 string newstr = fileContent.Replace( " xmlns: "" renew ");
                newstr = newstr.Replace( " xmlns "" topattr ");
                await FileIO.WriteTextAsync(file, newstr);
                fileContent = await FileIO.ReadTextAsync(file);
         // 按XML文件格式读取相应的节点

        。。。。
                
         // 再将文件内容还原回去
        newstr = newstr.Replace( " renew "" xmlns: ");
                newstr = newstr.Replace( " topattr "" xmlns ");
复制代码

 几经周折,我的需求是满足了,不知道各位还有没有别的更好的方法呢?

 

 

 

Trackback:

http://www.cnblogs.com/jing870812/archive/2012/06/18/2553978.html

转载于:https://www.cnblogs.com/hdjjun/archive/2012/07/03/2574969.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值