bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

i want to make <say></sya> so that it can be <say>hello world!</say>

use XML::Simple; my $xs = new XML::Simple(); my $ref = $xs->XMLin("<say>Hello world!</say>"); my $xml = $xs->XMLout($ref); print $xml; exit;

bt it brings <opt>hello world!</opt>

Replies are listed 'Best First'.
Re: xml help
by Corion (Patriarch) on Dec 11, 2014 at 18:03 UTC

    XML::Simple is not really a good XML parser.

    That said, you want to look at the KeepRoot option:

    #!perl -w use strict; use XML::Simple; my $xs = XML::Simple->new( KeepRoot => 1, ); my $ref = $xs->XMLin("<say>Hello world!</say>"); my $xml = $xs->XMLout($ref); print $xml; exit;
      an XML::Twig example to help bootstrap you:

      use strict; use warnings; use XML::Twig; my $twig = new XML::Twig('pretty_print' => 'indented'); $twig->safe_parse('<say/>'); my $root = $twig->root(); $root->set_text('Hello World'); $twig->print();

      The fine documentation should be read if you're going to use it. I haven't met a problem with XML that twig couldn't handle though.
      Thanks guys, both solution worked for me