【发布时间】:2017-07-05 16:41:45
【问题描述】:
我有以下字典结构
[{
"Body" : [{
"Universal Lift Support" : ["1\"-9\" Extended Length",
"10\"-14.5\" Extended Length",
"15\"-19\" Extended Length",
"20\" + Extended Length"]
}]
我想使用 dicttoxml 库来获得所需的 xml 输出,例如:
<root>
<Body>
<Universal Lift Support>
1"-9" Extended Length
10"-14.5" Extended Length
15"-19" Extended Length
20" + Extended Length
</Universal Lift Support>
但是,应用下一个代码后:
dicttoxml.dicttoxml(result, attr_type=False, root=True)
我得到了类似的 xml 结构:
<?xml version="1.0" encoding="UTF-8" ?><root><item><Body><item><Universal_Lift_Support><item>1&quot;-9&quot; Extended Length</item><item>10&quot;-14.5&quot; Extended Length</item><item>15&quot;-19&quot; Extended Length</item><item>
哪些选项可以帮助格式化和获取上述输出?
【问题讨论】:
-
如果您指的是
- ...
,您是否阅读过 dicttoxml 的文档,因为它是这么说的。请参阅pypi.python.org/pypi/dicttoxml 或者如果您指的是“Universal Lift Support”变成“Universal_Lift_Support”的事实,那么您不能在 xml 标签中包含空格。或者,如果您指的是您的文本已放在单独的项目中,那么空格在 xml 中并不重要,所以也许这就是 dicttoxml 选择表示多行文本的方式。基本上,您的“所需”翻译既不是有效的 xml,也不是 dicttoxml 默认的
标签: python json xml python-3.x dicttoxml