2013-04-30 54 views
0

假設我有一個XML文件:如何在Python中獲取節點的XML值?

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <quarkSettings> 
    <UpdatePath></UpdatePath> 
    <Version>Development</Version> 
    <Project>ABC</Project> 
    </quarkSettings> 
</configuration> 

現在我想獲得項目的價值。我寫了下面的代碼:

 import xml.etree.ElementTree as ET 
     doc1 = ET.parse("Configuration.xml") 
     for e in doc1.find("Project"): 
       project =e.text 

但它沒有給出值。

回答

0

我得到了答案:

import xml.etree.ElementTree as ET    
doc1 = ET.parse(get_path_for_config_Quark_Release) 
root = doc1.getroot() 
for element in root.findall("quarkSettings"): 
    project = element.find("Project").text