I am fresh to the new glorious World of XML,
and trying to figure out how this stuff melds together with perl.

I found http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
could somebody look over my code analysis and tell me if I am (nearly)
right?

require "files/camelid_links.pl"; # Needs the specified file to work.
my %camelid_links = get_camelid_data();
# Some function that greates the Hash (see section the Hash).


my $root = XML::Element->new('html'); # Creates the HTML Frame
<html></html>.
my $body = XML::Element->new('body'); # Creates the Body Frame <body></body>
my $xml_pi = XML::Element->new('~pi', text => 'xml version="1.0"');
# Creates the typicall XML-First Line <?xml version="1.0"?>
$root->push_content($body);
# Takes the  Body Frame and puts it into the HTML Frame
<html><body></body><html>

foreach my $item ( keys (%camelid_links) ) {
    my $link = XML::Element->new('a', 'href' =>
$camelid_links{$item}->{url});
    # creates a new <a href></a> tag, uses the url stored in $item (for
example "one") as the
    # reference. The whole stuff is the link object.
    $link->push_content($camelid_links{$item}->{description});
    # fills the stored description of for example "one" in the <a href></a>
framework
    $body->push_content($link);
    # puts the now ready <a href></a> object into the body framework (which
is already placed
    # in the html framework.)
} # does this for all the six urls we have in the hash.

print $xml_pi->as_XML; # prints the  <?xml version="1.0"?> as_XML ???? line
to stdout
print $root->as_XML(); # prints the punch of frameworks to stdout (as_XML
does what???)




############## The Hash ############################
my %camelid_links = (
    one   => { url         => '
    http://www.online.discovery.com/news/picture/may99/photo20.html',
               description => 'Bactrian Camel in front of Great ' .
                              'Pyramids in Giza, Egypt.'},
    two   => { url         =>
'http://www.fotos-online.de/english/m/09/9532.htm',
               description => 'Dromedary Camel illustrates the ' .
                              'importance of accessorizing.'},
    three => { url         => 'http://www.eskimo.com/~wallama/funny.htm',
               description => 'Charlie - biography of a narcissistic
llama.'},
    four  => { url         =>
'http://arrow.colorado.edu/travels/other/turkey.html',
               description => 'A visual metaphor for the perl5-porters ' .
                              'list?'},
    five  => { url         => 'http://www.galaonline.org/pics.htm',
               description => 'Many cool alpacas.'},
    six   => { url         =>
'http://www.thpf.de/suedamerikareise/galerie/vicunas.htm',
               description => 'Wild Vicunas in a scenic landscape.'}
);

###############################################

require "files/camelid_links.pl";
my %camelid_links = get_camelid_data();


my $root = XML::Element->new('html');
my $body = XML::Element->new('body');
my $xml_pi = XML::Element->new('~pi', text => 'xml version="1.0"');
$root->push_content($body);

foreach my $item ( keys (%camelid_links) ) {
    my $link = XML::Element->new('a', 'href' =>
$camelid_links{$item}->{url});
    $link->push_content($camelid_links{$item}->{description});
    $body->push_content($link);
}

print $xml_pi->as_XML;
print $root->as_XML();

##### Expected Results ##########################

<html>
  <body>
    <a href="http://www.eskimo.com/~wallama/funny.htm";>Charlie -
      biography of a narcissistic llama.</a>
    <a
href="http://www.online.discovery.com/news/picture/may99/photo20.html";>Bactr
ian
      Camel in front of Great Pyramids in Giza, Egypt.</a>
    <a href="http://www.fotos-online.de/english/m/09/9532.htm";>Dromedary
      Camel illustrates the importance of accessorizing.</a>
    <a href="http://www.galaonline.org/pics.htm";>Many cool alpacas.</a>
    <a href="http://arrow.colorado.edu/travels/other/turkey.html";>A visual
      metaphor for the perl5-porters list?</a>
    <a href="http://www.thpf.de/suedamerikareise/galerie/vicunas.htm";>Wild
      Vicunas in a scenic landscape.</a>
  </body>
</html>
##############################################



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to