Forum Discussion

smartTest's avatar
smartTest
Contributor
12 years ago

[Resolved]Remove Nodes from XML request - Groovy help needed

Hiya
I am working on a test case that uses a property transfer step to move a nodeset from a completed request into another request step. What I need to do before running the next request is to remove some elements of the transferred data but I can't seem to work out the Groovy script required to delete the unwanted nodes following. The request message I want to adjust is:

               <ota:PTC_FareBreakdown>
<ota:PassengerTypeQuantity Code="ADT" Quantity="2"/>
<ota:FareBasisCodes>
<ota:FareBasisCode FlightSegmentRPH="1">CIF</ota:FareBasisCode>
<ota:FareBasisCode FlightSegmentRPH="2">CIF</ota:FareBasisCode>
</ota:FareBasisCodes>
<ota:PassengerFare>
<ota:BaseFare Amount="6927.00" CurrencyCode="GBP" DecimalPlaces="2"/>
<ota:Taxes>
<ota:Tax TaxCode="GB" Amount="134.00"/>
<ota:Tax TaxCode="UB" Amount="39.75"/>
<ota:Tax TaxCode="AY" Amount="1.60"/>
<ota:Tax TaxCode="US" Amount="22.60"/>
<ota:Tax TaxCode="XA" Amount="3.30"/>
<ota:Tax TaxCode="XY" Amount="4.60"/>
<ota:Tax TaxCode="YC" Amount="3.60"/>
<ota:Tax TaxCode="XF" Amount="2.90"/>
</ota:Taxes>
<ota:TotalFare Amount="7139.35" CurrencyCode="GBP" DecimalPlaces="2"/>
<ota:UnstructuredFareCalc>LHR &lt;> EWR5220.76CIF &lt;> LHR5220.77CIF NUC10441.53END ROE0.663408</ota:UnstructuredFareCalc>
<ota:FareBaggageAllowance FlightSegmentRPH="1" UnitOfMeasureQuantity="" UnitOfMeasure=""/>
<ota:FareBaggageAllowance FlightSegmentRPH="2" UnitOfMeasureQuantity="" UnitOfMeasure=""/>
<ota:Remark>TKTG AGREEMENT DOES NOT EXIST FOR &lt;> SEE >DX*TA</ota:Remark>
<ota:Remark>LAST TKT DATE 23MAY13-DATE OF ORIGIN</ota:Remark>
<ota:Remark>UNABLE TO VERIFY BOOKING DATE</ota:Remark>
<ota:Remark>- DATE OF ORIGIN</ota:Remark>
<ota:Remark>NO BAGGAGE DISCLOSURE DATA FOR THIS REQUEST</ota:Remark>
<ota:Remark>IATA FARES USED FOR PRICING</ota:Remark>
</ota:PassengerFare>
</ota:PTC_FareBreakdown>

Where, for instance, I need to remove the <ota:TotalFare Amount="7139.35" CurrencyCode="GBP" DecimalPlaces="2"/> node altogether. I will have multiple of the <ota:PTC_FareBreakdown> nodesets in the request and need to remove the same data in all of them.

Can anyone help me with an easy script for this as I'm a newbie to Groovy scripting.

thanks in advance.
Di

2 Replies

  • Well I surprised myself and make my Groovy step work

    The code used for anyone else looking to do the same was:

    def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def ReqHolder = grUtils.getXmlHolder("completeBooking#Request")
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[1]/ota:PassengerFare[1]/ota:TotalFare[1]') //removes Fare Node
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[1]/ota:PassengerFare[1]/ota:FareBaggageAllowance[1]') //removes first FareBaggageAllowance node
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[1]/ota:PassengerFare[1]/ota:FareBaggageAllowance[1]') //removes second FareBaggageAllowance node
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[2]/ota:PassengerFare[1]/ota:TotalFare[1]') //removes Fare Node
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[2]/ota:PassengerFare[1]/ota:FareBaggageAllowance[1]') //removes first FareBaggageAllowance node
    ReqHolder.removeDomNodes('//cfb:completeBooking_RQ[1]/ota:PriceInfo[1]/ota:PTC_FareBreakdowns[1]/ota:PTC_FareBreakdown[2]/ota:PassengerFare[1]/ota:FareBaggageAllowance[1]') //removes second FareBaggageAllowance node
    ReqHolder.updateProperty()

    Very proud of myself and thankful for Google and this forum