1. Go to this page and download the library: Download rkr/xpath library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rkr / xpath example snippets
use Kir\XML\XPath\DomXPath;
use Kir\Streams\Impl\StringStream;
$stream = new PhpStream('tests/assets/test.html', 'r');
$xp = DomXPath::createFromHtmlStream($stream);
php_sapi_name() == 'cli' || print('<pre>');
foreach($xp->getNodes('//div') as $node) {
echo "{$node->getValue('./@title')}\n";
foreach($node->getNodes('./a') as $subNode) {
echo "\t{$subNode->getValue('.')}\n";
}
}
use Kir\XML\XPath\DomXPath;
use Kir\Streams\Impl\PhpStream;
$stream = new PhpStream('tests/assets/test.xml', 'r');
$xp = DomXPath::createFromXmlString($stream, ['a' => 'https://github.com/rkrx/php-xpath/products', 'b' => 'https://github.com/rkrx/php-xpath/product']);
php_sapi_name() == 'cli' || print('<pre>');
foreach($xp->getNodes('/a:products/b:product') as $no => $node) {
echo "{$no}\n";
echo "\t{$node->getValue('./b:name')}\n";
echo "\t{$node->getValue('./b:ref')}\n";
echo "\t{$node->getValue('./b:price')}\n";
echo "\t{$node->getValue('./b:stock')}\n";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.