Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order changed when seriallized to string #29

Open
danhamill opened this issue Aug 18, 2020 · 0 comments
Open

Order changed when seriallized to string #29

danhamill opened this issue Aug 18, 2020 · 0 comments

Comments

@danhamill
Copy link

danhamill commented Aug 18, 2020

For this dictionary:

{'Name': 'Shear',
 'Type': 'RASResultsMap',
 'Checked': 'True',
 'Filename': '.\\Test Plan\\Shear Stress (08Aug2020 08 00 00).vrt',
 'MapParameters': [{'MapType': 'Shear',
   'LayerName': 'Shear Stress',
   'OutputMode': 'Stored Current Terrain',
   'StoredFilename': '.\\Test Plan\\Shear Stress (08Aug2020 08 00 00).vrt',
   'Terrain': 'CBR_041619',
   'ProfileIndex': '576',
   'ProfileName': '08Aug2020 08:00:00',
   'ArrivalDepth': '0'}]}

and this processor:

ras_processor = xml.dictionary('Layer',[
                                xml.string('.', attribute='Name'),
                                xml.string('.', attribute='Type'),
                                xml.string('.', attribute='Checked'),
                                xml.string('.', attribute='Filename'),
                                xml.array(xml.dictionary('MapParameters', [
                                    xml.string('.', attribute = "MapType"),
                                    xml.string('.', attribute = 'LayerName'),
                                    xml.string('.', attribute = 'OutputMode'),
                                    xml.string('.', attribute = 'StoredFilename'),
                                    xml.string('.', attribute = 'Terrain'),
                                    xml.string('.', attribute = 'ProfileIndex'),
                                    xml.string('.', attribute = 'ProfileName'),
                                    xml.string('.', attribute = 'ArrivalDepth')
                                    ])
                                    )])

After I run xml.serialize_to_string(ras_processor, test, indent=' '). The order of the attributes has changed to alphabetical. I would prefer to have the same attribute order as the input dictionary. Can this be done?

<?xml version="1.0" encoding="utf-8"?>
<Layer Checked="True" Filename=".\Test Plan\Shear Stress (08Aug2020 08 00 00).vrt" Name="Shear" Type="RASResultsMap">
    <MapParameters ArrivalDepth="0" LayerName="Shear Stress" MapType="Shear" OutputMode="Stored Current Terrain" ProfileIndex="576" ProfileName="08Aug2020 08:00:00" StoredFilename=".\Test Plan\Shear Stress (08Aug2020 08 00 00).vrt" Terrain="CBR_041619"/>
</Layer>

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant