Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

6.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}});
}