Please try this perl code, I haven't used any external modules.
undef $/; open(IN,"<sample.xml") || die "can not open the input xml file"; open(OUT,">sample_out.xml") || die "can not open the out xml file"; $str=<IN>; close IN; $headera=""; $headerb=""; $footer="</bibdataset>"; $has=(); $headera=$& if ($str =~ /<\?xml.*\?>/si); $headerb=$& if ($str =~ /<bibdataset[^>]+>/si); while ($str =~ /<item>.*?<\/item>/gsi) { $con=$&; if ($con =~ /<itemid\s+idtype\s*=\s*\"PUI\">\s*(\d+)\s*<\/itemi +d>/) { $puino=$1; $has{$puino}=$con; } } print OUT $headera; print OUT $headerb; foreach $ke(sort keys %has) { print OUT $has{$ke}; } print OUT $footer; close OUT;
In reply to Re: Sort xml based on attribute
by vmsathiya
in thread Sort xml based on attribute
by bharathinc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |