1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Rep Power

    XML::Simple --> XMLout() problem

    Hello ppl,

    I would like to know if there is any idea based on XML::Simple and not other (i.e XML::LibXML)

    My problem is that I want to create an XML but avoid the sorting!!!

    I have properly created my structure :
    $xmlnode = {

    and then
    $xml = XML::Simple::XMLout($xmlNode, RootName => undef, nosort => 1);

    Even though I put that nosort => 1, it stills sorts my elements in the XML alphabetically.

    I know that this is difficult to avoid since it is stored as a hash, PERL is not able to verify the correct order... so it sorts it alphabetically by default

    So what is the reasone of that nosort option if it is not used??? and is there any way to solve this?

    My XML outputs are normally exported but the order of elemenents/attributes are in a mess

    Thanks and cheers
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Rep Power
    Hashes are unordered, so you should not expect the output to come out in any particular way.

    If the order of the XML is important to you, then you probably will have to use another method to exporting a data structure using XML::Simple

    - Miller
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power
    Saw this because I just ran into the same thing. Here's a kludgy workaround..

    1) prepend some string in front of your entries before putting into the hash which will cause it to be sorted the way you want, e.g.


    2) remove the strings just before writing the file
    my $xmlout = XMLout($xmlconfig_r, rootname => 'reportconfig')
    $xmlout =~ s/\dSORT_//g;
    print OUTFILE $xmlout;
    close (OUTFILE);

IMN logo majestic logo threadwatch logo seochat tools logo