안녕하세요, 특정 콘텐츠 또는 값이있는 모든 노드의 수를 계산하려고합니다.PHP 및 XML에서 특정 값을 포함하는 XML 노드 수 얻기
<hotel>
<city>Cancun</city>
<postalCode>77500</postalCode>
<countryCode>MX</countryCode>
<airportCode>CUN</airportCode>
<supplierType>E</supplierType>
<propertyCategory>1</propertyCategory>
<hotelRating>4.0</hotelRating>
<confidenceRating>52</confidenceRating>
</hotel>
내가 4의 값을 가진 모든 hotelRating을 찾아 내 XML 목록에 얼마나 많은 계산이 필요 :이 경우 I는 그래서 XML을 가지고있다. 나는 PHP로 이것을 어떻게하는지 모른다. 누구든지 이걸 도와 주면 너무 고맙겠습니다 !!
나는 XML 파일을 다음과 같이 연결했으며 데이터를 가져 와서 데이터를 보낼 수 있습니다.
$post_string= 'type=xml&cid=222&minorRev=14&apiKey=222&locale='.$userLocale.'¤cyCode='.$userCurr.'&customerIpAddress='.$userIp.'&customerUserAgent='.$userAgent.'&xml=<HotelListRequest><destinationId>'.$destinationId.'</destinationId><arrivalDate>'.$arriving.'</arrivalDate><departureDate>'.$departing.'</departureDate><RoomGroup>'.$xmlQuery.'</RoomGroup><supplierCacheTolerance>MED_ENHANCED</supplierCacheTolerance></HotelListRequest> ';
//Relative path to the file with $_POST parsing
$path = "http://api.ean.com/ean-services/rs/hotel/v3/list";
$ch = curl_init($path);
$fp = fopen('xml/data.xml','w');
//Send the data to the file
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
$val = curl_exec($ch);
curl_close($ch);//Close curl session
fclose($fp); //Close file overwrite
$data = simplexml_load_file('xml/data.xml');
}
사전에 도움을 주셔서 감사합니다 !!!