Home | Mirror | Search

5. XML::Simple

		
use strict;
use XML::Simple qw(:strict);

my $xml =q(<?xml version='1.0'?>
<library>
  <book>
    <isbn>0596001320</isbn>
    <title>Learning Perl, 3rd Edition</title>
    <author>Randal L. Schwartz</author>
    <author>Tom Phoenix</author>
  </book>
  <book>
    <isbn>1565922204</isbn>
    <title>Advanced Perl Programming</title>
    <author>Sriram Srinivasan</author>
  </book>
  <book>
    <isbn>076455106X</isbn>
    <title>Guitar for Dummies</title>
    <author>Mark Phillips</author>
    <author>John Chappell</author>
  </book>
</library>
);

my $library = XMLin($xml);

foreach my $book (@{$library->{book}}) {
  print "$book->{title}\n";
  print "  $_\n" foreach(@{$book->{author}});
}		
		
		
		
		
		
		
comments powered by Disqus