我正在使用可用的xml文件here。解析XML的最佳方法
我想解析并加载LON, LAT, PGA, PGV, MMI, PSA03, PSA10, PSA30, STDPGA, URAT and SVEL
作为CSV文件的标题。
grid_data
元素以空格定界符方式具有所有这些标头的所有值。
我要寻找一个csv file output
象下面这样:
LON LAT PGA PGV MMI PSA03 PSA10 PSA30 STDPGA URAT SVEL
-99.6833 38.2891 0.04 0.04 2.04 0.09 0.02 0 0.65 1 363.294
-99.6666 38.2891 0.04 0.04 2.06 0.09 0.02 0 0.65 1 342.531
-99.6500 38.2891 0.04 0.04 2.11 0.1 0.02 0 0.65 1 303.783
-99.6333 38.2891 0.04 0.04 2.08 0.09 0.02 0 0.65 1 334.629
-99.6166 38.2891 0.04 0.05 2.15 0.09 0.02 0 0.65 1 279.535
-99.6000 38.2891 0.04 0.04 2.08 0.09 0.02 0 0.65 1 326.391
-99.5833 38.2891 0.04 0.04 2.02 0.08 0.02 0 0.65 1 390.897
-99.5666 38.2891 0.04 0.04 2.08 0.09 0.02 0 0.65 1 346.033
后来,我用熊猫为蟒蛇找到PGV最大价值,做我的GIS分析。
到目前为止,这是我的代码:
import sys
import traceback
from xml.dom import minidom
import warnings
warnings.filterwarnings("ignore")
try:
print "*"*20 + " The Beginning " + "*"*20
xml_file_location = r"C:\Users\*****\Downloads\Grids\us2000a3y4_grid.xml"
xmldoc = minidom.parse(xml_file_location)
itemlist = xmldoc.getElementsByTagName('grid_field')
for item in itemlist:
print (item.attributes['name'].value)
Catch all exception and print to the screen
except:
e = sys.exc_info()[0]
print("Error: %s\n\n" % e)
#Closing script
finally:
print "*"*20 + " The End " + "*"*20
有你试过什么? –
编辑了这个问题并粘贴了我到目前为止的代码。 –
是否有任何错误?输出是什么? –