我正在使用可用的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
有你試過什麼? –
編輯了這個問題並粘貼了我到目前爲止的代碼。 –
是否有任何錯誤?輸出是什麼? –