http://www.perlmonks.org?node_id=259824

XML::Smart is out!

It's a smart, easy and powerful way to access/create XML data/files.

You access/create your XML data with a HASH tree style, but any point in the tree can be a HASH, ARRAY or SCALAR at the same time, so you don't need to care about the different types in the tree, you just us the tree and XML::Smart change it, or make it works like it, for you.

Download at:
http://search.cpan.org/author/GMPASSOS/XML-Smart-1.0/

Dependence:
http://search.cpan.org/author/GMPASSOS/Object-MultiType-0.01/

Here is an example of use:

use XML::Smart ; my $XML = XML::Smart->new('file.xml') ; ## Change the root: $XML = $XML->{hosts} ; ## Get the address [0] of server [0]: my $srv0_addr0 = $XML->{server}[0]{address}[0] ; ## Or just: my $srv0_addr0 = $XML->{server}{address} ; ## Get the server where the attibute 'type' eq 'suse': my $server = $XML->{server}('type','eq','suse') ; ## Add a new server node: my $newsrv = { os => 'Linux' , type => 'Mandrake' , version => 8.9 , address => [qw(192.168.3.201 192.168.3.202)] } ; push(@{$XML->{server}} , $newsrv) ; ## Get/rebuild the XML data: my $xmldata = $XML->data ; ## Save in some file: $XML->save('newfile.xml') ; ## Send through a socket: print $socket $XML->data(length => 1) ; ## show the 'length' in the XML header to the ## socket know the amount of data to read. __DATA__ <?xml version="1.0" encoding="iso-8859-1"?> <hosts> <server os="linux" type="redhat" version="8.0"> <address>192.168.0.1</address> <address>192.168.0.2</address> </server> <server os="linux" type="suse" version="7.0"> <address>192.168.1.10</address> <address>192.168.1.20</address> </server> <server address="192.168.2.100" os="linux" type="conectiva" version= +"9.0"/> </hosts>

Graciliano M. P.
"The creativity is the expression of the liberty".