我选择了以下元素:
>>> order
<Element Order at 0x10364b960>
要获得所有子元素,我可以这样做:
>>> order.getchildren()
[<Element Digital_Order at 0x10364b910>, <Element Identifier at 0x10364b8c0>,
<Element Sold_To_Party at 0x10364b9b0>, <Element Customer_PO_No at 0x10364ba00>,
<Element PO_Date at 0x10364ba50>, <Element Customer_Name at 0x10364baa0>,
<Element Buyer_Name at 0x10364baf0>, <Element Approval_Dt at 0x10364bb40>,
<Element Approval_By at 0x10364bb90>, <Element Order_Creation_Dt at 0x10364bbe0>,
<Element Order_Instructions at 0x10364bc30>, <Element Order_Items at 0x10364bc80>]
如何选择特定的孩子,在这种情况下Identifier
?
答案 0 :(得分:2)
使用order.find('Identifier')
检索第一个Identifier
子元素。
如果您想要一个包含所有匹配元素的数组,请使用findall
代替find
。
答案 1 :(得分:1)