I've used SimpleXMLReader to make parse of a gigantic XML structure, that has more than 25mb.
My code works normally, however, I have two problems:
I can not turn Xpath
into HTML
. Well, I studied it, and I saw that it's not an easy task, is it even possible to do that? It turns out that Xpath does not allow me to use the values inside a PHP string in the HTML code.
I can not limit the amount of items displayed. I've already looked at all the code in the simpleXMLreader.php file, but I see no way to limit the amount of items extracted from XML, I was told to use foreach
next to Xpath
in main code, I tried, but it did not work.
Download the SimpleXMLReader software here: https://github.com/dkrnl/SimpleXMLReader
My code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Boutique</title>
</head>
<body>
<?php header ('Content-type: text/html; charset=UTF-8'); ?>
<link rel="stylesheet" href="/va/artigos-complexos/afilio/afilio-vitrine.css" type="text/css" />
<div class="mainproductebayfloatright-bottom">
<?php
require_once dirname(__FILE__). "/simplexmlreader.php";
class ExampleXmlReader1 extends SimpleXMLReader
{
public function __construct()
{
// by node name
$this->registerCallback("nome", array($this, "callbackNome"));
$this->registerCallback("preco_promocao", array($this, "callbackPrice"));
}
protected function callbackNome($reader)
{
$xml = $reader->expandSimpleXml();
$name = $xml;
$xpath = $this->currentXpath();
echo "$xpath: Nome = $name;\n";
return true;
}
protected function callbackPrice($reader)
{
$xml = $reader->expandSimpleXml();
$preco_promocao = $xml;
$xpath = $this->currentXpath();
echo "$xpath: Preço = $preco_promocao;\n";
return true;
}
}
echo "<pre>";
?>
<div class="aroundebay">
<div id="aroundebay2">
<?php
print "<div class=\"titleebay\"><a rel=\"nofollow\" href=\"$link_produto\">" . $title . "</a></div>";
print "<div class=\"mainproduct\"><a rel=\"nofollow\" href=\"$link\"><img style=\"height:120px\" src=\"$imagem\"/><br/>";
//print "De:; R$". $preco_normal . "<br/>";
print "<span>Apenas R$" . $preco_promocao . "<br/></a></span></div>";
//print "Em " . $parcelas . "x de : R$" . $vl_parcelas . "</a></span></div>";
?>
</div>
</div>
</div>
<?php
//Pega o arquivo pelo caminho relativo
//$file = dirname(__FILE__) . "/boutique.xml";
$reader = new ExampleXmlReader1;
// Pega o arquivo pela URL. Original: $reader->open($file);
$reader->open("http://v2.afilio.com.br/aff/aff_get_boutique.php?boutiqueid=37930-895987&token=53e355b0a09ea0.74300807&progid=1010&format=XML");
$reader->parse();
$reader->close();
?>
</body>
</html>
PS: CSS is not relevant.