我正在尝试分析我的 XML 文件,我想获取数据 XYZ 以便稍后进行高级分析,然后绘制所有值。这里的 XML 文件如下所示:
<UserPosition>
<X>-12.2934008394709</X>
<Y>52.488259963403273</Y>
<Z>-0.92276278637695341</Z>
</UserPosition>
这是我的代码:
from lxml import etree
import matplotlib.pyplot as plt
import numpy as np
# Read xml files
PostX = []
PostY= []
Thikness = []
tree = etree.parse("XMLFILE.xml")
for UserPosition in
tree.xpath("/cResult/measure/lMeasuredItem/cMeasureItem/UserPosition/X"):
PostX.append(UserPosition.text)
print PostX
我明白了!:
['-12.2934008394709','-9.1133008238197366','-5.9329608027622784','-2.7523007917339029',
任何帮助获得适当的分析值。
有什么理由不能改变
PostX.append(UserPosition.text)
至
PostX.append(float(UserPosition.text))
否则,查看所有 x、y 和 z 值(或当然更多)在此 .xml 文件中的结构会很有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句