0

次のXMLがあるとしましょう

<InvoiceLines>
            <InvoiceLine>
                <InsertionDate>29.01.2015</InsertionDate>
                <Productnbr>0102</Productnbr>
            </InvoiceLine>
            <InvoiceLine>
                <InsertionDate>29.02.2015</InsertionDate>
                <Productnbr>0103</Productnbr>
            </InvoiceLine>
</InvoiceLines>

Productnbr = 0103 の InvoiceLine の挿入日を取得したいと思います。xpath を記述する場合、次のように記述します。

//InvoiceLine[./Productnbr='0103']/InsertionDate

しかし、コードで XMLSlurper を使用しているため、GPath を使用したいと考えています。GPath に述語を適用する方法はありますか? ありがとうございました

4

1 に答える 1

0

ツリー検索を使用して、findその子の値を取得できます。

def date = new XmlSlurper().parseText(xml)
                           .'**'
                           .find { it.Productnbr == '0103' }?.InsertionDate
于 2015-07-02T15:19:26.510 に答える