xmlfix02.pl to HTML.

index -|- end

Generated: Tue Feb 2 17:55:01 2010 from xmlfix02.pl 2007/08/25 1.7 KB.

#!/perl -w
# NAME: xmlfix02.pl
# AIM: exploring add keyattr => [key, tag] to new
# BUT AS FAR AS I CAN TELL THEY ARE EXACTLY THE SAME!!!
# can not use 'strict' with [key, tag] ...
# 25/08/2007 geoff cmalne - geoffair.net/mperl/
#use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
require 'logfile.pl' or die "Unable to load logfile.pl ...\n";
# log file stuff
my ($LF);
my $pgmname = $0;
if ($pgmname =~ /\w{1}:\\.*/) {
   my @tmpsp = split(/\\/,$pgmname);
   $pgmname = $tmpsp[-1];
}
my $outfile = "temp.$pgmname.txt";
open_log($outfile);
prt( "$0 ... Hello, World ...\n" );
my ($xs1, $ref1, $xml1, $dx1, $cnt1);
my ($xs2, $ref2, $xml2, $dx2, $cnt2);
my @lines1 = ();
my @lines2 = ();
my $in_file = 'Banan.xml';
#- XmlSimpleKey.pl
$xs1 = new XML::Simple(keeproot => 1,searchpath => ".",
  forcearray => 1); # default is: keyattr => [name, key, id])
$ref1 = $xs1->XMLin($in_file);
$xml1 = $xs1->XMLout($ref1);
prt( "\nHash dump with 'keyattr => [name, key, id]':\n" );
$dx1 = Dumper($ref1);
prt( $dx1 );
prt( "\nXML output with 'keyattr => [name, key, id]':\n" );
prt( $xml1 );
prt( "\n" );
$xs2 = new XML::Simple(keeproot => 1,searchpath => ".",
  forcearray => 1, keyattr => [key, tag]);
$ref2 = $xs2->XMLin($in_file);
$xml2 = $xs2->XMLout($ref2);
prt( "\nHash dump with 'keyattr => [key, tag]':\n" );
$dx2 = Dumper($ref2); 
prt( $dx2 );
prt( "\nXML output with 'keyattr => [key, tag]':\n" );
prt( $xml2 );
@lines1 = split("\n",$dx1);
@lines2 = split("\n",$dx2);
$cnt1 = scalar @lines1;
$cnt2 = scalar @lines2;
prt( "1 $cnt1 lines, 2 $cnt2 lines\n" );
write2file($dx1, "temp1.txt");
write2file($dx2, "temp2.txt");
write2file($xml1, "temp11.txt");
write2file($xml2, "temp22.txt");
close_log($outfile,1);
exit(0);
# eof

index -|- top

checked by tidy  Valid HTML 4.01 Transitional