We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
''' dicttoxml pip install dicttoxml pip install xmltodict ''' import dicttoxml import os from xml.dom.minidom import parseString d = [20,'names',{'name':'Bill','age':30,'salary':2000}, {'name':'Mike','age':40,'salary':3000}, {'name': 'John', 'age': 20, 'salary': 1000}] bxml = dicttoxml.dicttoxml(d,custom_root='persons') xml = bxml.decode('utf-8') print(xml) dom = parseString(xml) ## string 转 xml prettyxml = dom.toprettyxml(indent=' ') ## 设置缩进 print(prettyxml) f = open('files/persons1.xml','w',encoding='utf-8') f.write(prettyxml) f.close()
<?xml version="1.0" ?> <persons> <item type="int">20</item> <item type="str">names</item> <item type="dict"> <name type="str">Bill</name> <age type="int">30</age> <salary type="int">2000</salary> </item> <item type="dict"> <name type="str">Mike</name> <age type="int">40</age> <salary type="int">3000</salary> </item> <item type="dict"> <name type="str">John</name> <age type="int">20</age> <salary type="int">1000</salary> </item> </persons>
需要2个第三方模块(需要安装)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
需要2个第三方模块(需要安装)
The text was updated successfully, but these errors were encountered: