Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Adding elements using XML::Simple

by grantm (Parson)
on Apr 29, 2003 at 10:49 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://253934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found