1#!/usr/bin/perl 2use XML::TinyXML; 3use Data::Dumper; 4$Data::Dumper::Sortkeys = 1; 5 6my $hash = { 7 a => 'b' , 8 c => 'd', 9 hash => { 10 key1 => 'value1', 11 key2 => 'value2' 12 }, 13 array => [ 14 "arrayval1", 15 { subhashkey => 'subhashvalue' }, 16 [ # XXX - folded arrays will be flattened by actual implementation 17 { nome1 => 'subarray1' } , 18 { nome2 => 'subarray2' , 'nome2.5' => 'dfsdf'}, 19 { nested => { nested2_1 => 'nestedvalue', nested2_2 => 'nestedvalue2' } }, 20 "subarrayval1", 21 "subarrayval2" 22 ] 23 ] 24}; 25 26 27my $txml = XML::TinyXML->new($hash); 28printf("%s \n", $txml->dump); 29 30my $testnode = $txml->getNode("/txml/a"); 31print "node a _ ".$testnode->value . " (".$testnode->name .") \n"; 32 33printf("%s \n", $txml->getRootNode(1)->countChildren); 34my @children = $txml->getRootNode(1)->children; 35 36warn Dumper(\@children); 37 38print "Original hash: \n"; 39warn Dumper($hash); 40print "Reimported hash: \n"; 41warn Dumper($txml->toHash); 42undef($txml); 43#my $txml2 = XML::TinyXML->new(); 44#$txml2->loadBuffer($txml->dump); 45 46#warn Dumper($txml2->toHash); 47#printf("%s \n", $txml2->dump); 48 49my $txml = XML::TinyXML->new(); 50$txml->loadFile("./t/t.xml"); 51printf("%s \n", $txml->dump); 52my $testnode = $txml->getNode("/xml/foo"); 53print Dumper($testnode); 54print $testnode->name ."\n"; 55foreach my $k ($testnode->children) { 56 print $k->type . "\n"; 57} 58 59 60