Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Sort n Create XML

by roman (Monk)
on Aug 20, 2007 at 11:00 UTC ( [id://633765]=note: print w/replies, xml ) Need Help??


in reply to Sort n Create XML

I'm used to use XML::LibXML and XPath
use strict; use warnings; use XML::LibXML; my $doc = XML::LibXML->new->parse_file('abc.xml'); my @class_elems = $doc->findnodes('/*/class'); my @sorted_class_elems = sort { $a->findvalue('strength') <=> $b->findvalue('strength') } @class_elems; for my $node (@class_elems) { $node->replaceNode( shift(@sorted_class_elems)->cloneNode(1) ); } open( my $fh, '>', 'xyz.xml' ); $fh->print( $doc->toString(1) );
Roman

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://633765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found