declxml
declxml copied to clipboard
Order changed when seriallized to string
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!