XML-Simple - Re: XML::Simple Sorting

Posted on Thu Nov 22 00:41:38 2007 by tirto in response to 6494 (See the whole thread of 3)
Re: XML::Simple Sorting
got it! thank you very much for your prompt response. i will modify my data structure. hash_to_array wasn't part of the "hook methods", it would be nice to include hash_to_array in the doc. btw, i was going to use XML::Filter::Sort in an attempt to solve the problem, but it wasn't giving what i want, not to mention that i have to change my data structure anyways and deal with the array folding if i don't supply keyattr option. your suggested solution is much better.
#!/usr/local/bin/perl -w use strict; use warnings; use XML::Simple; use XML::Filter::Sort; use XML::SAX::Writer; my $hashref = { item => { "2" => { label => 'bar' }, "1" => { label => 'foo' }, "11" => { label => 'baz'}, } }; my $writer = XML::SAX::Writer->new(); my $filter = XML::Filter::Sort->new(Handler=>$writer, Record=>'item', Keys => [['name', 'num', 'asc']]); my $xs = XML::Simple->new(Handler=>$filter); my $xml = $xs->XMLout( $hashref, NoAttr=>1); print $xml;
output:
<?xml version='1.0'?><opt> <item> <name>1</name> <label>foo</label> </item> <item> <name>2</name> <label>bar</label> </item> <item> <name>11</name> <label>baz</label> </item> </opt>0
it weird that it's giving me 0 at the end of the xml output. thanks again, tirto
Write a response