use strict; use Data::Dumper; #require XML::Simple;# qw(:strict); use XML::Simple;# qw(:strict); # # I've got two xml files. The 1st contains 1 project the 2nd contains 2. # I need XML::Simple to create the same data structure every time. # How do I do this? # # Creates $tree->{project}{name} equal to 'PlayGround'. # But I don't want that. # I want $tree->{project}{'PlayGround'}. # my $xmldata1=<
EOF &xml1($xmldata1); # # I like how this structure is created. # How do I get this structure all the time? # my $xmldata2=<
EOF &xml1($xmldata2); # --------------- show xml data. sub xml1 { my $data=shift; print "data\n$data\n"; my $simple = XML::Simple->new( ); my $tree = $simple->XMLin( $data #,forcearray=>0,KeyAttr => [ ] # creates array for 2nd file. #,forcearray=>0 # no affect #,forcearray=>0 # no affect #,forcearray=>0,KeyAttr => [ ],ValueAttr => { project => 'name' } #,VarAttr => 'name' # no affect #,ValueAttr => { project => 'name' } # no affect #,ValueAttr => [ 'name' ] # no affect #,KeyAttr => { project => "+name" } # no affect #,KeyAttr => { project => 'name' } # no affect #,ForceContent => 1 # no affect ); print "0", Dumper( $tree ); print "1", Dumper( $tree->{project}{name} ); # don't want this. print "2", Dumper( $tree->{project}{'PlayGround'} ) ; # want this all the time. print "-" x 79, "\n"; } #### E:\bin\XML>xmlqna.pl data
0$VAR1 = { 'project' => { 'name' => 'PlayGround', 'state' => { 'Emergency' => {}, 'Development' => {} } } }; 1$VAR1 = 'PlayGround'; 2$VAR1 = undef; ------------------------------------------------------------------------------- data
0$VAR1 = { 'project' => { 'PlayGround' => { 'state' => { 'Emergency' => {}, 'Development' => {} } }, 'GymClass' => { 'state' => { 'Emergency' => {}, 'Development' => {} } } } }; 1$VAR1 = undef; 2$VAR1 = { 'state' => { 'Emergency' => {}, 'Development' => {} } }; -------------------------------------------------------------------------------