0

我选择了以下元素:

>>> 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

4

2 回答 2

2

用于order.find('Identifier')检索第一Identifier个子元素。

如果您想要一个包含所有匹配元素的数组,请使用findall而不是find.

于 2012-06-24T21:02:38.857 回答
1

lxml中的anElement是一棵完整的树,所以可以随意使用findorfindall方法:

order.find('Identifier')

换句话说,它的工作原理与首先查找您的订单元素相同。

于 2012-06-24T21:03:44.167 回答