Comment analyser multi enregistrer fichier XML ues XML::Simple en Perl

Mon data.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <cd country="UK">
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <price>10.0</price>
  </cd>
  <cd country="CHN">
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <price>9.99</price>
  </cd>
  <cd country="USA">
    <title>Hello</title>
    <artist>Say Hello</artist>
    <price>0001</price>
  </cd>
</catalog>

mon test.pl

#!/usr/bin/perl

   # use module
   use XML::Simple;
   use Data::Dumper;

   # create object
   $xml = new XML::Simple;

   # read XML file
   $data = $xml->XMLin("data.xml");

   # access XML data
   print "$data->{cd}->{country}\n";
   print "$data->{cd}->{artist}\n";
   print "$data->{cd}->{price}\n";
   print "$data->{cd}->{title}\n";

De sortie:

Not a HASH reference at D:\learning\perl\t1.pl line 16.

Commentaire: j'ai googlé et trouvé l'article(poignée unique xml record).
http://www.go4expert.com/forums/showthread.php?t=812
J'ai testé avec le code article, il fonctionne très bien sur mon ordinateur portable.

Puis j'ai créé ma pratique de code ci-dessus pour essayer d'accéder à de multiples enregistrement. mais a échoué. Comment puis-je résoudre ce problème? Merci.

InformationsquelleAutor Nano HE | 2010-06-04