0

lets say I have the following XML

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

and I would like to get the insertion date of InvoiceLine that has Productnbr = 0103. If I would write xpath I would write somthing like:

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

but I would like to use GPath since I am using XMLSlurper in my code. Is there a way how to apply predicate to GPath? Thank you

jazzyekim
  • 101
  • 1
  • 10

1 Answers1

0

You can use a tree search with find and then get the value of it's child:

def date = new XmlSlurper().parseText(xml)
                           .'**'
                           .find { it.Productnbr == '0103' }?.InsertionDate
tim_yates
  • 167,322
  • 27
  • 342
  • 338