I want to convert xml (qml) file to dictionary, then convert this dictionary to new xml. (Also want to edit something, but first lets just convert it in both way without it.)

I'm using xmltodict module to xml->dict and then dicttoxml module,dom parse to string and file.write() to dict->xml.

    xml = open("path",  "r")
    org_xml = xml.read()
    dict_xml = xmltodict.parse(org_xml)

    new_xml = dicttoxml.dicttoxml(dict_xml, custom_root = 'qgis')
    dom = (parseString(new_xml)).toprettyxml()

    with open("path/new.qml", 'a') as file:

The problem is, that while converting I 'loose' something. First file is a categorized symbol style tempale and the second is single symbol.

Anyone tried conversion like this and can help?

closed as off-topic by PolyGeo Jul 5 '17 at 21:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


I just realized that the problem was in dictoxml or dom parsing. I changed my code a bit everything works nicely:

xml = open(path, "r")
org_xml = xml.read()
dict_xml = xmltodict.parse(org_xml, process_namespaces=True)

out = xmltodict.unparse(dict_xml, pretty=True)
with open("path/new.qml", 'a') as file:

Not the answer you're looking for? Browse other questions tagged or ask your own question.