[SimpleXML] lecture du chemin xpath
Désolé c'est un peu basique comme question, mais je débute,
mon expression Xpath n'est pas correct puisque
mon tableau Array reste vide, je recherche des produits
par ville à partir du fichier xml avec cette structure
et code php dessous
Merci d'avance pour un conseil
manuso
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<?xml version="1.0" encoding="utf-8" ?>
- <products xmlns="http://zzz.fusepumpaffiliates.co.uk/feed-distribution/">
- <product>
<lastUpdated></lastUpdated>
<title></title>
<url></url>
<thumbnailUrl></thumbnailUrl>
<currency></currency>
<destination>Strasbourg</destination>
<destinationCountry>France</destinationCountry>
<destinationCountryCode>FR</destinationCountryCode>
</product>
- <product> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
<?
define('NB_PAR_PAGE', 10);
// On récupère le num de page sur laquelle on est pagination
$city="Strasbourg";
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$document = ('simplexml_load_file('http://zzz.clickline.co.uk/feed-distribution');
// Test 1
$count = count($document->xpath(utf8_encode("//products/product[destination=\"$city\"]")));
// Test 2
$count = count($document->xpath(utf8_encode("//products/product/lastUpdated/title/url/thumbnailUrl/currency[destination=\"$city\"][position()>=$debut_pos and position()<$fin_pos]"));
$debut_pos = ($page - 1) * NB_PAR_PAGE + 1;
$fin_pos = $page * NB_PAR_PAGE + 1;
$derniere_page = ceil($count / NB_PAR_PAGE);
$produits = $document->xpath(utf8_encode("//products/product/lastUpdated/title/url/thumbnailUrl/currency[destination=\"$city\"][position()>=$debut_pos and position()<$fin_pos]"));
print_r($produits);
?> |