Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 5 — Storing and Sharing Information 75


You can see the resulting XML generated from this file in Listing 5-10.


Listing 5-10: An XML File Generated from Fixed-Width File Data


145
1385674
Martin
Brown
United Kingdom


383
4897947
Mickey
Mouse
United States


384
2349875
Donald
Duck
United States


In Listing 5-10, all of the data is stored within a tag, individual records are con-
tained within a tag, and individual fields are contained by appropriate
individual tags.


For a more flexible programmable interface for building XML files in Perl, you can use the
XML::Generatormodule. The module provides a very flexible method for creating XML
and even nested XML. You can see a sample of this in Listing 5-11.


Listing 5-11: Generating XML with XML::Generator

use XML::Generator;


my $gen = XML::Generator->new(‘escape’ => ‘always’,
‘pretty’ => 2);


my $restaurants = {‘One on Wharf’ => {longitude => -0.64,
latitude => 52.909444},
Continued

Free download pdf