Help for this page

Select Code to Download


  1. or download this
    ## The data:
    <?xml version="1.0" encoding="iso-8859-1"?>
    ...
      </server>
      <server address="192.168.2.100" os="linux" type="conectiva" version=
    +"9.0"/>
    </hosts>
    
  2. or download this
      my $xml = new XML::Simple();
      my $tree = $xml->XMLin(DATA]);
    
      my $addr0 = $tree->{hosts}{server}[0]{address}[0] ;
      my $addr1 = $tree->{hosts}{server}[1]{address} ;
    
  3. or download this
      my $XML = XML::Smart->new(DATA) ;
      
    ...
      my $addr1 = $XML->{hosts}{server}[1]{address}    ; ## return {addres
    +s}
      ## ...or..
      my $addr1 = $XML->{hosts}{server}[1]{address}[0] ;  ## return {addre
    +ss}
    
  4. or download this
      my $addr = $XML->{hosts}{server}('type','eq','conectiva'){address} ;
    
  5. or download this
    ## Data:
    <foo port="80">content<i>a</i><i>b</i></foo>
    ...
    $HASH = (
    foo => { i => ['a','b'] , CONTENT => 'content' }
    );
    
  6. or download this
      my $cont = $XML->{foo} ;
      ## ...or...
    ...
    
      print "<<$cont>>\n" ; ## print: <<content>>
      $content .= 'x' ; ## Append data.
    
  7. or download this
      my $data = $XML->data ;
    
      ## Directly to the file:
      my $data = $XML->save('new.xml') ;