我是 Groovy / GPath 的新手,并且正在将它与 RestAssured 一起使用。我需要一些有关查询语法的帮助。
给定以下 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'}.@Num");
如何提取 AllowChild="true" 的所有座位号?
我试过了:
List<String> childSeatNos = response.extract().xmlPath().getList("**.findAll { it.name() == 'Seat' & it.@AllowChild() == 'true'}.@Num");
它抛出:
java.lang.IllegalArgumentException: Path '**'.findAll { it.name() == 'Seat' & it.@AllowChild() == 'true'}.'@Num' is invalid.
什么是正确的语法?