ssr1012 ssr1012 - 2 years ago 66
Perl Question

How to avoid the attribute interchanging in xml while using XML::Twig in perl

In my input xml file we are doing some conversions work in perl. And we need to have the xml file with indentation. Hence we are using the Module

(Simple way) for pretty indent.

In perl code:

XML::Twig->new( pretty_print => 'indented')
->parsefile( $input )
->print_to_file( $input);


<contrib contrib-type="author" id="U94028797" corresp="yes">

After doing this function the tool has been interchanging the attribute's in xml elements.


<contrib contrib-type="author" corresp="yes" id="U94028797">

Anyone give suggestion to avoid this and it would be appreciated. Thanks in advance.

Answer Source

Use the keep_atts_order option when you create the twig: docs

You will need Tie::IxHash to be installed.

Note that XML tools should not care at all about the order of the attributes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download