I have a list of integers [22,23,64,65,9] and what is the best way to store it over an xml file
<cls>
<cl value="22" />
<cl value="23" />
<cl value="64" />
<cl value="65" />
<cl value="9" />
</cls>
I now have the above structure and is it advisable to use the same ? my end goal is to parse it back to python list.
Your snippet is all right, but something like
<cls>22,23,64,65,9</cls>
would be OK and faster if parsed by python like this:
[int(x) for x in xml_string.split(",")]
because the xml parser has less work to iterate on the nodes. The "all in one" approach is shorter in bytes (because you don't need <cl value="" /> so the data is way smaller, particularly on a big list), and thus consumes less resources (always time various approaches).
The only issues I'm seeing:
strtok to parse, and a lot of tedious string operations to create. So if you share your format with a C program, the C coder will hate you for this :)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With