Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Adding elements using XML::Simple

by grantm (Parson)
on Apr 29, 2003 at 10:49 UTC ( #253934=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    <opt>
      <trans>
        <idnumber1 status="not contacted" assignee="jack" />
      </trans>
    </opt>
    
  2. or download this
    <opt>
      <trans>
    ...
        <idnumber2 status="contacted" assignee="jill" />
      </trans>
    </opt>
    
  3. or download this
    <opt>
      <trans>
        <item id="1" status="not contacted" assignee="jack" />
      </trans>
    </opt>
    
  4. or download this
    <opt>
      <trans>
    ...
        <item id="2" status="contacted" assignee="jill" />
      </trans>
    </opt>
    
  5. or download this
    my $xs = XML::Simple->new(
      forcearray => [ 'item' ], 
    ...
    );
    
    my $opt = $xs->XMLin(\*DATA);
    
  6. or download this
     
      $opt->{trans}->{item}->{1}
    
  7. or download this
      $opt->{trans}->{item}->{2} = { status => 'contacted', assignee => 'j
    +ill' };
    
  8. or download this
    #!/usr/bin/perl -w
    
    ...
      <item id="1" status="not contacted" assignee="jack" />
     </trans>
    </opt>
    
  9. or download this
      $opt->{trans}->{item}->[0]
    
  10. or download this
      @{ $opt->{trans}->{item} }
    
  11. or download this
      my $id = @{ $opt->{trans}->{item} } + 1;
    
      push @{ $opt->{trans}->{item} }, { id => $id, status => 'contacted',
    + assignee => 'jill' };
    
  12. or download this
    #!/usr/bin/perl -w
    
    ...
      <item id="1" status="not contacted" assignee="jack" />
     </trans>
    </opt>
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://253934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-09-20 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls