Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

66 Part I — Basics


Before the XML is generated, you need to store and retrieve information from your own
databases for use with your applications. Choosing the right format for storing the data is,
therefore, critical. The three potential solutions are flat-text files; Extensible Markup Language
(XML); and database systems such as a Structured Query Language (SQL) Relational
Database Management System (RDBMS) like MySQL, PostgreSQL, or SQL Server.

Using Flat-Text Files


A flat-text file is just a text file with some very basic formatting or organizational information.
For example, the common format output by database or spreadsheet software is the comma-
separated values (CSV ) file, in which a carriage return separates individual records and a
comma separates individual fields in each record. Another variation is the tab-delimited file
(TDF), which uses tabs to separate field data. You can also use other formats and separators
according to your needs and requirements.

Reading and extracting information from a flat-text file is easy, especially with the modern
scripting languages often used within web development. You can use a scripting language to
convert your original source flat-file text into XML, the format you need for Google Maps.
You can also use flat-text as a method for extracting or transferring information from other
sources (for example, an Excel spreadsheet) into a database for use or processing.

However, although adding information to the end of a text file is also relatively easy, deleting
or editing the information in the file is difficult. The only way to delete or edit is to read the
file up the point where you want to add or change the data, add the updated or new informa-
tion, and then continue writing the remainder of the original data.

Of course, you may ask yourself, “If I have to use XML for Google Maps, why not just use
XML to store the data in the first place, rather than converting the stored data to XML from
another format?”

Using XML


Storing information in XML has its advantages from the perspective that, in its native format,
you can use XML data with the Google Maps API to update and display information. Storing
the data for your application in XML can, therefore, simplify the entire process.

However, XML is not a format that is easy to write by hand. Although converting most types
of information from the source format to XML through a simple program or script is generally
quite straightforward, the layout and format of XML information does not lend itself to easy
manipulation. Even with efficient tools like XPath, which enables you to reference specific
areas of a given XML file by working through the XML tags, updating the information still
relies on the same basic methods as updating bare text files: You seek to the location you want
to change, you modify the text, and then you write out the new version.

But although XML is not an ideal storage mechanism for the information on the server
end, XML is the data format you’ll use to exchange information with Google Maps. For this
reason, you must examine more closely how to produce and parse XML documents with your
application.
Free download pdf