Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:


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(] } ; 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></address> <address></address> </server> <server os="linux" type="suse" version="7.0"> <address></address> <address></address> </server> <server address="" os="linux" type="conectiva" version= +"9.0"/> </hosts>

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

In reply to ANNOUNCE: XML::Smart 1.0 by gmpassos

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2019-12-16 09:57 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found