Python parsing of attributes from XML to JSON and viceversa (JSON to XML)

I appreciate your help on the following python question:

I have an xml which looks like this:

                    <element name="firstElement">11111</element>
                    <element name="secondElement">2222</element>

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

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

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:

                            <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.

Read more here: Source link