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

Dear Monks,

I was wondering (again), is it possible to replace the <anon> tag for something else. Example:
#! /usr/bin/perl use XML::Simple ; my $doc->[0] = { a => 'a', b => 'b' } ; print $xs1->XMLout($doc, noattr => 1, xmldecl => '<?xml version="1.0">');
Output is :
<?xml version="1.0"> <opt> <anon> <a>a</a> <b>b</b> </anon> </opt>
For example, in my case I would like to replace it for <record>
Also interesting for me, can I replace <opt> for something else ?

Thank in advance Luca

Replies are listed 'Best First'.
Re: how to replace the <anon> tag (XML::Simple)
by GrandFather (Saint) on Apr 19, 2006 at 10:51 UTC
    use strict; use warnings; use XML::Simple ; my @doc = { a => 'a', b => 'b' } ; my $xs = new XML::Simple(RootName => 'something_else'); print $xs->XMLout({record => \@doc}, noattr => 1, xmldecl => '<?xml version="1.0">');

    Prints:

    <?xml version="1.0"> <something_else> <record> <a>a</a> <b>b</b> </record> </something_else>

    DWIM is Perl's answer to Gödel
      I'm puzzled by the curlies on your line

      my @doc = { a => 'a', b => 'b' } ;

      Shouldn't it read

      my @doc = ( a => 'a', b => 'b' ) ;

      I guess I'm missing something obvious.

      Cheers,

      JohnGG

        or:

        my %doc = (a => 'a', b => 'b');

        OP's code was so syntacticlly challenged that that (introduced) foible sliped through while I was cleaning up the issues raised by adding the strictures.

        The result is the same in this case in any case and is not pertinent to OP's problem - but worth pointing out.


        DWIM is Perl's answer to Gödel