I try to get all BrowseNodeId of the following XML file:
<?xml version="1.0" ?>
<ItemSearchResponse xmlns="http://ift.tt/1puqasB">
<OperationRequest>
<RequestId>00ffd0c4-65b8-40ed-96b3-dbee109c508e</RequestId>
<Arguments>
<Argument Name="Condition" Value="All"></Argument>
<Argument Name="region" Value="com"></Argument>
</Arguments>
<RequestProcessingTime>0.0428190000000000</RequestProcessingTime>
</OperationRequest>
<Items>
<Request>
<IsValid>True</IsValid>
<ItemSearchRequest>
<Condition>All</Condition>
<Keywords>0321185587</Keywords>
<ResponseGroup>BrowseNodes</ResponseGroup>
<SearchIndex>Books</SearchIndex>
</ItemSearchRequest>
</Request>
<TotalResults>1</TotalResults>
<TotalPages>1</TotalPages>
<Item>
<ASIN>0321185587</ASIN>
<BrowseNodes>
<BrowseNode>
<BrowseNodeId>21</BrowseNodeId>
<Name>Reference</Name>
<Children>
<BrowseNode>
<BrowseNodeId>11444</BrowseNodeId>
<Name>Almanacs & Yearbooks</Name>
</BrowseNode>
<BrowseNode>
<BrowseNodeId>11448</BrowseNodeId>
<Name>Atlases & Maps</Name>
</BrowseNode>
<BrowseNode>
<BrowseNodeId>2572</BrowseNodeId>
<Name>Careers</Name>
</BrowseNode>
</Children>
</BrowseNode>
</BrowseNodes>
</Item>
</Items>
</ItemSearchResponse>
Here is the PHP code I used:
$xml= simplexml_load_file($xml_file);
foreach ($xml->xpath('//BrowseNode') as $node) {
echo $node->BrowseNodeId.":".$node->Name."<br>";
}
But the result is NULL. I am not good at XML so I cannot figure out where I was wrong. Can anybody show me the correct xpath syntax for this case?
No comments:
Post a Comment