2014-12-02 35 views
0

下面的代碼:LXML ns_clean =真不出現工作

NAMESPACES = {'ns': 'http://www.starstandard.org/STAR/5', 'ns1': 'http://www.openapplications.org/oagis/9'} 
ro_xml = '{}.xml'.format(6001265) 
parser = etree.XMLParser(ns_clean=True) 
tree = etree.parse(ro_xml) 
root = etree.tostring(tree.getroot()) 
# print root 
residence = [] 
residence_address = '//ns:ResidenceAddress/*' 
shop_supplies_amount = tree.xpath(residence_address, namespaces=NAMESPACES) 
for child in shop_supplies_amount: 
    residence.append("%s: %s" % (child.tag, child.text)) 
print residence 

當我運行此我得到的命名空間中的標籤名稱的前面,像這樣'{http://www.starstandard.org/STAR/5}LineOne: 10757 RIVER FRONT PARKWAY'

我在做什麼錯誤以及如何擺脫標籤名稱前的命名空間

回答

0

我想通了一個方法。

NAMESPACES = {'ns': 'http://www.starstandard.org/STAR/5', 'ns1': 'http://www.openapplications.org/oagis/9'} 
ro_xml = '{}.xml'.format(6001265) 
parser = etree.XMLParser(ns_clean=True) 
tree = etree.parse(ro_xml, parser) 

vehicle = {} 
vehicle_info = tree.xpath(twc.XML_VEHICLE_INFO, namespaces=NAMESPACES) 
for child in vehicle_info: 
    vehicle.update({child.tag: child.text}) 
model = residence['{%s}Model' % NAMESPACES['ns']] 
print model 

不是最乾淨的我承認,但它讓我在我需要的地方。