You are here: SimpleXML and xpath woes « PHP « IT news, forums, messages
SimpleXML and xpath woes

Posted by Simon Turvey on 03/16/05 19:39

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация