2017-10-17 1 views
1

私はGroovy/GPathの新人で、RestAssuredでそれを使用しています。クエリの構文に関する助けが必要です。次のXMLスニペットを考えるGPath Groovy文でAND句を使用して、> 1の条件に一致するすべてのXMLノードを取得します。

<?xml version="1.0" encoding="UTF-8"?> 
<SeatOptions FlightNumber="GST4747" AircraftType="737" NumberOfBlocks="2" Currency="GBP" Supplier="ABC"> 
    <Seat Num="1A" Availabile="true" BandId="1" Block="1" Row="1" AllowChild="false" /> 
    <Seat Num="1B" Availabile="true" BandId="1" Block="1" Row="1" AllowChild="false" /> 
    <Seat Num="1C" Availabile="true" BandId="1" Block="1" Row="1" AllowChild="false"/> 
    <Seat Num="1D" Availabile="true" BandId="1" Block="2" Row="1" AllowChild="false" /> 
    <Seat Num="1E" Availabile="true" BandId="1" Block="2" Row="1" AllowChild="true" /> 
    <Seat Num="1F" Availabile="true" BandId="1" Block="2" Row="1" AllowChild="true" /> 
</SeatOptions> 

を次のように私はすべての座席番号を抽出することができます。

List<String> allSeatNos = response.extract().xmlPath().getList("**.findAll { it.name() == 'Seat'}[email protected]"); 

にはどうすればAllowChild = "true" をすべての座席番号を抽出することができますか?

私が試してみました:

List<String> childSeatNos = response.extract().xmlPath().getList("**.findAll { it.name() == 'Seat' & [email protected]() == 'true'}[email protected]"); 

それはスロー:

java.lang.IllegalArgumentException: Path '**'.findAll { it.name() == 'Seat' & [email protected]() == 'true'}.'@Num' is invalid. 

正しい構文は何ですか?

答えて

0

論理AND演算子の場合は&&を使用し、ビット単位の "and"演算子の場合は&ではありません。リストにNumフィールドを抽出するために使用広がり演算子*[email protected](ない[email protected]

フィールドを参照する

response."**".findAll { it.name() == 'Seat' && [email protected] == 'true'}*[email protected] 
+0

ありがとうございます。しかし、私はまだIllegalArgumentExceptionを受けているので、ステートメント内に文法的なエラーが残っていると思います。 – Steerpike

+0

@Steerpike式に2つの構文エラーが見つかりました。答えは –

+0

です。ありがとうございました – Steerpike

関連する問題