Does XML :: Simple support ordering when using arrays?

I use XML :: Simple to parse the XML file, which I then want to use to write the output file in a very specific format. Thus, the output order is important. As far as I understand, when XML is converted to perl hashref, the order is lost (since perl hashes are not ordered). But what about when the array is used by XML :: Simple.

For instance:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <price>10.0</price>
  </cd>
  <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <price>9.99</price>
  </cd>
  <cd>
    <title>Hello</title>
    <artist>Say Hello</artist>
    <price>0001</price>
  </cd>
</catalog>

gives us a data structure resembling:

$VAR1 = {
      'cd' => [
              {
                'artist' => 'Bonnie Tyler',
                'price' => '10.0',
                'title' => 'Hide your heart'
              },
              {
                'artist' => 'Dolly Parton',
                'price' => '9.99',
                'title' => 'Greatest Hits'
              },
              {
                'artist' => 'Say Hello',
                'price' => '0001',
                'title' => 'Hello'
              }
            ]
    };

Structures 3 'cd' are inserted into the array, so their order will always be the same as in the input file?

+3
source share
2 answers

, , POD FAQ XML:: Simple, - .

, - , - - , .

:

  • XML:: Simple , . , XMLin = = datastructure, , XML:: Simple ( ); XML:: Simple code, , .

    , HARDER, , .

  • , POD unit test, .

+1

, . . , , XML:: Simple.

0

Source: https://habr.com/ru/post/1767908/


All Articles