How to change attribute order in xml twig using perl script?



I am new to xml twig, i want change attribute order, i don't know how to change this? is it possible to change attribute place change....


Input.xml



<?xml version="1.0" encoding="utf-8"?>
<root>
<product markup="xml" type="books" id="book1">
<name>Analysis</name>
<prize>$203</prize>
<subject>Construct</subject>
</product>
<product markup="xml" type="books" id="book2">
<name>Analysis</name>
<prize>$203</prize>
<subject>Bio</subject>
</product>
</root>


I need as:



<?xml version="1.0" encoding="utf-8"?>
<root>
<product **id="book1"** markup="xml" type="books">
<name>Analysis</name>
<prize>$203</prize>
<subject>Construct</subject>
</product>
<product **id="book2"** markup="xml" type="books">
<name>Analysis</name>
<prize>$203</prize>
<subject>Bio</subject>
</product>
</root>


My code is:



my $XML = XML::Twig->new(
twig_handlers =>{
#'product' => sub {$_},
(i don't know this process)
},
pretty_print => 'record',
output_encoding => 'utf-8',
keep_atts_order => 1,
);
$XML->parsefile("input.xml");
$XML->purge;


how to change this...


No comments:

Post a Comment