Windows 8 學習筆記(十四)–.map檔案與.kml檔案的解析

來源:互聯網
上載者:User
這段時間在做一個通過從網路上抓取的.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");

 幾經周折,我的需求是滿足了,不知道各位還有沒有別的更好的方法呢?

     

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.