有一个xml文件
<ns:Documents
xmlns:ns="http://fsrar.ru/WEGAIS/WB_DOC_SINGLE_01"
xmlns:wb="http://fsrar.ru/WEGAIS/TTNSingle_v4">
<ns:Document>
<ns:WayBill_v4>
<wb:Header>
<wb:Shipper>
</wb:Shipper>
<wb:Consignee>
</wb:Consignee>
</wb:Header>
</ns:WayBill_v4>
</ns:Document>
</ns:Documents>
我需要找一个收货人节点,或者Consignee
写了这段代码
import xml.etree.cElementTree as et
tree = et.parse( "WayBill.xml" )
root = tree.getroot()
wb_Consignee = root.find( 'wb:Consignee' )
print( wb_Consignee ) # None
Consignee = root.find( 'Consignee' )
print( Consignee ) # None
告诉我出了什么事?
@splash58 建议在哪里挖掘。感谢他。2-3小时的训练,一切都变好了
这是结果
更短的版本,使用 XPath