tags:

views:

340

answers:

1

I'm creating an XML file using Perl and XML::Simple module. I successfully create the XML file, but the problem is I am having <opt> </opt> tag for each my tags. I am looking for any option which we can aviod the <opt> </opt> tag. I can't do the post-processing to remove the tag. because the file size is huge.

Example :

<opt>
  <person firstname="Joe" lastname="Smith">
    <email>[email protected]</email>
    <email>[email protected]</email>
  </person>
  <person firstname="Bob" lastname="Smith">
    <email>[email protected]</email>
  </person>
</opt>

and I am looking for (without <opt> tag):

  <person firstname="Joe" lastname="Smith">
    <email>[email protected]</email>
    <email>[email protected]</email>
  </person>
  <person firstname="Bob" lastname="Smith">
    <email>[email protected]</email>
  </person>
+6  A: 

The tag is the root element of the XML generated from the user-supplied data-structure. From the XML::Simple documentation -

RootName => 'string' # out - handy

By default, when XMLout() generates XML, the root element will be named 'opt'. This option allows you to specify an alternative name.

Specifying either undef or the empty string for the RootName option will produce XML with no root elements. In most cases the resulting XML fragment will not be 'well formed' and therefore could not be read back in by XMLin(). Nevertheless, the option has been found to be useful in certain circumstances.

To set the root element to blank just pass RootName as 'undef' to XMLout, for eg.

use XML::Simple;

my $xml = XMLout($hashref, RootName => undef);
muteW