I had XML files like this:
<root>
<key0>value</key0>
<key1>value</key1>
<key2>value</key2>
</root>
It’s easy to turn such file into key-value structure. Let’s showcase the result in Python dict, for example:
{'key0': 'value', 'key1': 'value', 'key2': 'value'}
Now they added nested elements:
<root>
<key0>value</key0>
<key1>value</key1>
<key2>value</key2>
<key3>
<sth0>value</sth0>
<sth1>value</sth1>
</key3>
</root>
Still easy:
{'key0': 'value', 'key1': 'value', 'key2': 'value', 'key3/sth0': 'value', 'key3/sth1': 'value'}
I think you got the point. Now what about this?
<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>
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.
Append something unique to the end of each name. Like becomes Key0_unique , where unique is a ascending number or guid.
(Although if your ‘ecosystem’ is big now and growing, I would consider sorting this out now rather than later.)