Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 chanting in the Monastery: (11)
As of 2015-07-06 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls