嗨,这是一个返回旅行套餐列表的网络服务:
<offerlist>
<id_o>154672521</id_o>
<Pax>04</Pax>
<FlightPackage>
<Type>Circle</Type>
<FlightSegment>
<Direction>Outbound</Direction>
<AvailabilityInfo>Available</AvailabilityInfo>
<Id>20180316|FCO|HAV|BV1554|Y|</Id>
<ProductType>ITC</ProductType>
<Source>PressTours</Source>
<AirlineCode>BV</AirlineCode>
<AirlineName>Blue Panorama</AirlineName>
<FlightNumber>BV1554</FlightNumber>
<DepartureAirportIataCode>FCO</DepartureAirportIataCode>
<ArrivalAirportIataCode>HAV</ArrivalAirportIataCode>
<StopAirportIataCode>CYO</StopAirportIataCode>
<DepartureDateTime>2018-03-16T08:00:00</DepartureDateTime>
<ArrivalDateTime>2018-03-16T16:35:00</ArrivalDateTime>
<ShamDateTime>false</ShamDateTime>
<CabinClass>Y</CabinClass>
<Warnings>
<Warning>
<Id>1</Id>
<Type>Critical</Type>
<Text>E' prevista una franchigia bagaglio etnica di 1 collo dal peso massimo di 32 kg per i passeggeri con passaporto cubano che viaggiano in classe Economica e di 2 colli dal peso massimo di 32kg cadauno per i passeggeri con passaporto cubano che viaggiano Comfort Class.</Text>
<StartingDate>2009-11-01T00:00:00</StartingDate>
<EndingDate>2100-01-01T00:00:00</EndingDate>
</Warning>
<Warning>
<Id>118</Id>
<Type>Critical</Type>
<Text>La richiesta impegnativa di posti eccedenti la nostra disponibilità pre-acquistata (puntino giallo), comporta un maggior costo in ragione della disponibilità di classe del vettore al momento della prenotazione. Il supplemento per la classe economy è di almeno € 35 per persona a tratta.</Text>
<StartingDate>1950-01-01T00:00:00</StartingDate>
<EndingDate>2050-12-31T00:00:00</EndingDate>
</Warning>
</Warnings>
</FlightSegment>
<FlightSegment>
<Direction>Inbound</Direction>
<AvailabilityInfo>Available</AvailabilityInfo>
<Id>20180329|HAV|FCO|NO0430.|Y|</Id>
<ProductType>ITC</ProductType>
<Source>PressTours</Source>
<AirlineCode>NO</AirlineCode>
<AirlineName>Neos</AirlineName>
<FlightNumber>NO0430.</FlightNumber>
<DepartureAirportIataCode>HAV</DepartureAirportIataCode>
<ArrivalAirportIataCode>FCO</ArrivalAirportIataCode>
<StopAirportIataCode>CUN</StopAirportIataCode>
<DepartureDateTime>2018-03-29T19:40:00</DepartureDateTime>
<ArrivalDateTime>2018-03-30T15:00:00</ArrivalDateTime>
<ShamDateTime>false</ShamDateTime>
<CabinClass>Y</CabinClass>
<Warnings>
<Warning>
<Id>118</Id>
<Type>Critical</Type>
<Text>La richiesta impegnativa di posti eccedenti la nostra disponibilità pre-acquistata (puntino giallo), comporta un maggior costo in ragione della disponibilità di classe del vettore al momento della prenotazione. Il supplemento per la classe economy è di almeno € 35 per persona a tratta.</Text>
<StartingDate>1950-01-01T00:00:00</StartingDate>
<EndingDate>2050-12-31T00:00:00</EndingDate>
</Warning>
<Warning>
<Id>2</Id>
<Type>Critical</Type>
<Text>E' prevista una franchigia bagaglio etnica di 40 kg. E' necessario fornire il numero di passaporto.</Text>
<StartingDate>2009-11-01T00:00:00</StartingDate>
<EndingDate>2100-01-01T00:00:00</EndingDate>
</Warning>
</Warnings>
</FlightSegment>
</FlightPackage>
<Dest>Cuba</Dest>
<Loc>Varadero</Loc>
<Struct>Memories Varadero Beach Resort 4 Stelle</Struct>
<idd>{b6a475f2-ef5e-4d9f-8cb7-a7d8dff43114}</idd>
<idl>{55251786-7e22-4684-89b4-7e708df5527e}</idl>
<ids>1VRASIRENIS</ids>
<S_type>Pack</S_type>
<Plan>AI</Plan>
<DptDate>2018-03-16T00:00:00</DptDate>
<days>15</days>
<nights>13</nights>
<dptapt>FCO</dptapt>
<price>1632.12</price>
<insur>160</insur>
<visatx>213.69</visatx>
<promo>: 0 € sul valore del volo e dell'hotel - Condizioni da Offerta Vacanze ai Caraibi!!!: 8,00% per persona a notte sul valore dell'hotel - Condizioni da Offerta</promo>
<scontoapplicato>3,45% pari a Euro 58,24</scontoapplicato>
<catoff>O</catoff>
<commoff>11</commoff>
<Status>M</Status>
<modDate>2018-02-27T00:21:41</modDate>
<av_from>0001-01-01T00:00:00</av_from>
<av_to>0001-01-01T00:00:00</av_to>
</offerlist>
我让Larave从webservice $xml2 = simplexml_load_file($url)
解析它。
我需要检查航班节点是否至少有一个状态可用,我可以导入包,否则不会。
有人可以解释我如何计算具有特定值的事件出现在孩子身上吗?
答案 0 :(得分:0)
您可以使用xpath表达式执行此操作:
/offerlist/FlightPackage/FlightSegment/AvailabilityInfo[text() = 'Available']
例如:
$items = $xml2->xpath("/offerlist/FlightPackage/FlightSegment/AvailabilityInfo[text() = 'Available']");
echo count($items);
在示例中,这将为您提供2个xml。
如果您有多个商品详情,可以这样做。
首先获取所有//offerlist
并循环获取计数:
$xml2 = simplexml_load_file("http://localhost/v1.xml");
$offerlists = $xml2->xpath("//offerlist");
foreach ($offerlists as $offerlist) {
echo sprintf("Offerlist with id: %s has %s times 'Available'.<br>",
$offerlist->id_o,
count($offerlist->xpath("./FlightPackage/FlightSegment/AvailabilityInfo[text() = 'Available']"))
);
}