Windows 8 Study Notes (14th)-. Map File and. kml File Parsing

Source: Internet
Author: User
During this period of time, we are doing a task that is crawled from the network. map File and region image, load and locate the corresponding, and output the navigation path. kml format, so that the last path is displayed in the next load. If you have used Google Earth, you should know these two file formats .. Map File Parsing this file is not an XML file format, but it has an inherent output order. I only need to extract the information I want in a fixed order. Of course, I have the most stupid method here, this method is too versatile to intercept in the form of character lines, but I really don't know which method to use. If I know it, I still forget to tell ~ 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 File Parsing kml files are XML file formats, but there are subtle differences, it has header files <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">

In this format, the file cannot be loaded in C #. I took another step in the middle and replaced the xmlns: kml format with the normal XML file format, after reading the data, write it back to the file.

. Kml File Reading

View code

 
Fileopenpicker filepicker = new fileopenpicker ();
Filepicker. filetypefilter. Add (". kml ");
Filepicker. viewmode = pickerviewmode. thumbnail;
Storagefile file = await filepicker. picksinglefileasync ();
// Kml file escape
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 );
// Read the corresponding node in XML file format

....

// Restore the File Content
Newstr = newstr. Replace ("renew", "xmlns :");
Newstr = newstr. Replace ("topattr", "xmlns ");

After some twists and turns, my demand is met. I don't know if you have any better solutions?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.