topical media & game development

talk show tell print

professional-xml-18-perl-readcustomers.pl / pl



  use XML::Simple;
  use Data::Dumper;
  
  my file = 'customers.xml';
  
  # default behaviour
  print "Default behaviour\n";
  my doc = XMLin(file);
  print XMLout(doc->{customer}->{ALFKI});
  print "\n============================\n";
  
  # Coerces structure into arrays (outputs as elements)
  print "Output as elements\n";
  my doc = XMLin(file, ForceArray=>1);
  print XMLout(doc->{customer}->{ALFKI});
  print "\n============================\n";
  
  # Does not use id as key, creates array of customers
  print "Display 0th customer\n";
  my doc = XMLin(file, KeyAttr=>[]);
  print XMLout(doc->{customer}->[0]);
  print "\n============================\n";
  
  # Return selected elements
  print "Return selected elements\n";
  my doc = XMLin(file);
  print doc->{customer}->{AROUT}->{contact}->{phone}, "\n";
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.