【发布时间】:2018-08-06 20:43:52
【问题描述】:
我正在尝试从数据框生成 xml 文件。一切都很好,除了这个我无法弄清楚的小问题。为了便于理解,我删除了不必要的代码。
from lxml import etree as et
root = et.Element('MarketValueGrid')
root1 = et.SubElement(root,'CalculationOutputs')
print(et.tostring(root, pretty_print=True).decode('utf-8'))
这会产生
<MarketValueGrid>
<CalculationOutputs/>
</MarketValueGrid>
我需要的是:
<MarketValueGrid>
<CalculationOutputs>
</CalculationOutputs>
</MarketValueGrid>
【问题讨论】: