Possible Duplicate:
Xpath fails if an element has a a xmlns attribute
I have been trying for a long time to extract a string from the following xml with no luck
http://chris.photobooks.com/xml/default.htm?state=8T
I am trying to get the ASIN number of a book and I have tried
$xpath->query('//MarketplaceASIN/ASIN')->item(0)->nodeValue;
and
$xpath->query('/GetMatchingProductResponse/GetMatchingProductResult[1]/Product/Identifiers/MarketplaceASIN/ASIN')->item(0)->nodeValue;
but neither seem to work, what am I doing wrong here?
The elements in that document are bound to the namespace
http://mws.amazonservices.com/schema/Products/2011-10-01.You may have missed it because it does not use a namespace-prefix and the
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"just looks like an attribute, but namespace attributes are special.All of the descendant elements inherit that namespace. You will want to register the namespace with a namespace-prefix and adjust your XPath:
Or you could use a more generic XPath that matches on elements and uses a predicate filter to match the
local-name()andnamespace-uri():