Lalmani Kashyap
Lalmani Kashyap

Reputation: 21

How we extract multiple parameter in Xpath from XML including condition

Unable to extract the all values from Xpath from multiple tags with condition

Example: Extract all parameters :CarrierCode,DepartureDate,Destination,OperatingFlightNumber with condition PtcId=1.

<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">   <s:Body>
    <RetrievePaxAndSeatsByFlightResponse xmlns="departurecontrol.YYZ.com/v1">
      <RetrievePaxAndSeatsByFlightResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <Exceptions xmlns="contracts.base.test.com/v1"/>
        <Success xmlns="contracts.base.test.com/v1">true</Success>
        <AssignedSeats>
          <SeatAssignDisplay>
            <CarrierCode>xx</CarrierCode>
            <DepartureDate>2024-08-19T00:00:00</DepartureDate>
            <Destination>RRR</Destination>
            <OperatingFlightNumber>102</OperatingFlightNumber>
            <Origin>ZZZ</Origin>
            <Cabin>ECONOMY</Cabin>
            <ConfirmationNum>6ER49E</ConfirmationNum>
            <PtcId>1</PtcId>
            <RowNum>x</RowNum>
            <Seat>A</Seat>
            <TravelsWithInf>false</TravelsWithInf>
          </SeatAssignDisplay>
          <AssignedSeats>
          <SeatAssignDisplay>
            <CarrierCode>1D</CarrierCode>
            <DepartureDate>2024-08-19T00:00:00</DepartureDate>
            <Destination>MMM</Destination>
            <OperatingFlightNumber>102</OperatingFlightNumber>
            <Origin>NNN</Origin>
            <Cabin>ECONOMY</Cabin>
            <ConfirmationNum>6ER49E</ConfirmationNum>
            <PtcId>2</PtcId>
            <RowNum>5</RowNum>
            <Seat>A</Seat>
            <TravelsWithInf>false</TravelsWithInf>
          </SeatAssignDisplay>
          </RetrievePaxAndSeatsByFlightResult>
    </RetrievePaxAndSeatsByFlightResponse>   </s:Body> </s:Envelope>

we want the Xpath Extracted look like below but not working //Envelope/Body/RetrievePaxAndSeatsByFlightResponse/RetrievePaxAndSeatsByFlightResult/AssignedSeats[1]/SeatAssignDisplay[1]/Origin[1]/PtcId=1

Upvotes: 0

Views: 39

Answers (1)

Ivan G
Ivan G

Reputation: 2732

It would be as simple as:

//SeatAssignDisplay[PtcId='1']/CarrierCode

Demo:

enter image description here

More information:

Upvotes: 0

Related Questions