使用python为fusion图表创建data.xml文件
我是python的新手。我只是想知道如何创建代码来为fusioncharts编写xml文件名data.xml。xml文件的格式如下:使用python为fusion图表创建data.xml文件,python,fusioncharts,Python,Fusioncharts,我是python的新手。我只是想知道如何创建代码来为fusioncharts编写xml文件名data.xml。xml文件的格式如下: <?xml version="1.0" encoding="UTF-8" ?> <graph caption="Test graph" xAxisName="X" yAxisName="Y" showAnchors="1" anchorRadius="1" showValues="0"> <set name='2004' value=
<?xml version="1.0" encoding="UTF-8" ?>
<graph caption="Test graph" xAxisName="X" yAxisName="Y" showAnchors="1" anchorRadius="1" showValues="0">
<set name='2004' value='37800' color='AFD8F8' />
<set name='2005' value='21900' color='F6BD0F' />
<set name='2006' value='32900' color='8BBA00' />
<set name='2007' value='39800' color='FF8E46' />
</graph>
谢谢。您可以使用内置于python 2.0及更高版本中的miniDOM库: 来自stdlib的可能会有所帮助:
import xml.etree.cElementTree as etree
G = etree.Element('graph', dict(caption='Test graph', xAxisName="..."))
for name, value, color in get_sets():
etree.SubElement(G, 'set', dict(name=name, value=value, color=color))
etree.ElementTree(G).write(open('data.xml', 'wb'),
encoding='utf-8', xml_declaration=True))
在中有一个很好的例子,其中大部分也适用于Python2.x,如果您使用的是Python2.x的话。在开始使用Python时,该书/网站对于许多其他主题来说也是一个极好的总体资源