80 Part I — Basics
contain an interface to the DOM system. You may be familiar with the DOM interface,
because the DOM enables you to access elements of an HTML document by name (for exam-
ple, you can obtain the value of a form field by using the DOM to access the value by name).
Listing 5-16 shows an HTML fragment from which you can extract the information in each
field by using the code in Listing 5-17.
Listing 5-16: A Simple HTML Form
<form name=”personal” action=”index.cgi”>
<input type=text size=20 name=name>
<input type=text size=20 name=longitude>
<input type=text size=20 name=latitude>
</form>
Listing 5-17: Accessing the Form Data by Name Using DOM/JavaScript
document.personal.name
document.personal.longitude
document.personal.latitude
The term documentrefers to the entire HTML document (when used within JavaScript,
it typically means the current HTML document). The term personalrelates to the form
(which was given the name personal), and name,longitude, and latituderefer to the
field names within that form.
When working with XML, the basic rules for parsing the content through DOM are identical
to the structures you saw earlier when processing documents in this format through Perl.
The key way in which you use XML and the DOM system within Google Maps is to expose
data in XML format and use this data within your Google Maps application to create map
points, vectors, and other information.
Google Maps provides an XML HTTP interface (GXmlHttp) that can load XML documents
from a server. The resulting information is then accessible using the DOM interface, enabling
you to extract the relevant data from the XML and use it within the JavaScript application and,
ultimately, Google Maps.
Listing 5-18 shows the JavaScript model (and associated Google Maps commands) to add map
points to a map when provided with the XML file generated in Listing 5-12.