SimpleXML and xpath woes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

(Apologies for the larger than normal wrapping - there are some long lines)

I'm playing with SimpleXML for reading REST responses from Amazon Web Services.
Having successfuly read the response to my request I'd like to perform an xpath query
on the result.  I've pared down the original response to a static XML file for testing
purposes containing the following:

<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-02-23";>
	<OperationRequest>
		<HTTPHeaders>
			<Header Name="UserAgent"/>
		</HTTPHeaders>
		<RequestId>0MTRFP41HYDBPAEM41Q5</RequestId>
		<Arguments>
			<Argument Name="Service" Value="AWSECommerceService"/>
			<Argument Name="SubscriptionId" Value="055S8QK9GNAKPNMYQZ02"/>
			<Argument Name="ItemId" Value="0201788977"/>
			<Argument Name="Operation" Value="ItemLookup"/>
		</Arguments><RequestProcessingTime>0.0166029930114746</RequestProcessingTime>
	</OperationRequest>
	<Items>
		<Request>
			<IsValid>True</IsValid>
			<ItemLookupRequest>
				<ItemId>0201788977</ItemId>
			</ItemLookupRequest>
		</Request>
		<Item>
			<ASIN>0201788977</ASIN>				
			<ItemAttributes>
				<Author>Hesham Soliman</Author>
				<ProductGroup>Book</ProductGroup>
				<Title>Mobile IPv6 : Mobility in a Wireless Internet</Title>
			</ItemAttributes>
		</Item>
	</Items>
</ItemLookupResponse>

The code looks like this:

	$xml = simplexml_load_file('test.xml');
	$result = $xml->xpath($query);
	var_dump($result);

When:
	$query = '//*';

Everything is fine and an enormous array of matching elements is returned. However, when:

	$query = '//ItemLookupResponse';

var_dump returns:

	array(0) {
	}

Either a) I'm doing something terribly wrong (and I thought that I was attempting a pretty
simple xpath query) or b) SimpleXML's broken.

I'd prefer a) - it's easier to fix :)

Thanks a bunch,

Simon Turvey

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux