1
votes

I appreciate your help on the following python question:

I have an xml which looks like this:

 <properties>
            <replace>
                    <element name="firstElement">11111</element>
                    <element name="secondElement">2222</element>
                           etc.

I'm using xmltodic and it parses it like this:

{
    "properties": {
        "replace": {
            "element": [
                {
                    "@name": "firstElement",
                    "#text": "11111"
                },
                {
                    "@name": "secondElement",
                    "#text": "2222"
                }
            etc.

then when I convert it back to xml, I'm not getting the original structure. I have tried dicttoxml and json2xml and both give me this structure which doesn't match the original one:

<properties>
            <replace>
                    <element>
                            <key name="@name">firstElement</key>
                            <key name="#text">11111</key>
                            <key name="@name">secondElement</key>
                            <key name="#text">2222</key>

                   this format doesn't look as the original one!

Do you know any pair of modules (xml to json and json to xml) that would produce the correct attribute format ?

Thanks a lot for your help.