Improvement of the documentation for force_list when parsing XML with xmltodict
When parsing XML data with xmltodict, the problem often occurs that if only one
There are two approaches to solving this:
An explicit check to see if the return value is a dictionary, and then converting it to a list. The use of the parameter force_list, e.g. force_list=('Item',), to ensure that the key “Item” is always returned as a list. Since the force_list parameter is only briefly mentioned in the current xmltodict documentation and is not fully documented, I suggest extending the documentation. Specifically, it should explain how force_list is used and the advantages and limitations of this parameter. It would also be helpful to include examples that illustrate the difference between the two approaches.
Thank you very much for your attention and I look forward to your feedback.
This sounds reasonable. Feel free to send a pull request to address this.
We expanded the README’s API Reference with detailed force_list usage and examples. Closing as ‘docs clarified’.