rickya100 3 Junior Poster in Training

Hi there,

I am wondering if anyone here could tell me where I am going wrong with my XPath query. What I am using is below and is supposed to return me the URL attribute of the last Image element under the AccommodationSegment element.

The if statement keeps getting run saying mainImage is empty.

foreach( $xml->AccommodationSearchResponse->Accommodations->AccommodationSegment as $h ){

$mainImage = $h->xpath('/Image[last()]/@URL');


if($mainImage == ""){
	echo "<p>mainImage is not set</p>";
}

echo $mainImage;

If anyone has any tips for me I'd really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.