garryholliwell
New Member
I had XML files like this:\[code\]<root> <key0>value</key0> <key1>value</key1> <key2>value</key2></root>\[/code\]It's easy to turn such file into key-value structure. Let's showcase the result in Python dict, for example:\[code\]{'key0': 'value', 'key1': 'value', 'key2': 'value'}\[/code\]Now they added nested elements:\[code\]<root> <key0>value</key0> <key1>value</key1> <key2>value</key2> <key3> <sth0>value</sth0> <sth1>value</sth1> </key3></root>\[/code\]Still easy:\[code\]{'key0': 'value', 'key1': 'value', 'key2': 'value', 'key3/sth0': 'value', 'key3/sth1': 'value'}\[/code\]I think you got the point. Now what about this?\[code\]<root> <key0>value</key0> <key1>value</key1> <key1> <inner>value</inner> </key1> <key2>value</key2> <key3> <sth0>value</sth0> <sth1>value</sth1> </key3> <key3> <sth0>different value</sth0> <sth1>different value</sth1> </key3> <key3> <sth0>blah blah</sth0> <sth1>blah blah</sth1> </key3></root>\[/code\]Of course, I could come up with something after a while of thinking, but something tells me I would meet more and more difficulties. So the question is: Is there an complex algorithm to 'serialize' values in similarly simple XML file into key-value form? It has to be deterministically serializable and unserializable and no values can be lost. Order of elements doesn't matter (Python dict in examples is not a random choice, it's really what I'm trying to get).I know XMLs can be very complex (namespaces, attributes, whatever), but this is not the case. The only problem I need to properly resolve is nested values as presented and related multiplicity of the same keys.