<?php
header("Content-Type: text/plain; charset=UTF-8");
require_once "classes/css-parser/css-parser.php";
// loads an xml document
$doc = new DOMDocument("1.0", "UTF-8");
$doc->load('test.xml');
// equal attribute filter example
$query = "books item[author_id = 'eduardo-mendoza']";
echo "** Select \"$query\":\n";
$nodes = CSSHelper::select($doc, $query);
foreach ($nodes as $node) {
echo CSSHelper::dom2str($node) . "\n~~~\n";
}
echo "\n";
// id filter example
$query = "books item#7";
echo "** Select \"$query\":\n";
$nodes = CSSHelper::select($doc, $query);
foreach ($nodes as $node) {
echo CSSHelper::dom2str($node) . "\n~~~\n";
}
echo "\n\n";
// pseudo filter example
$query = "books item:nth-child(2)";
echo "** Select \"$query\":\n";
$nodes = CSSHelper::select($doc, $query);
foreach ($nodes as $node) {
echo CSSHelper::dom2str($node) . "\n~~~\n";
}
echo "\n";
// multiple filters example
$query = "books .sci-fi[author_id = isaac-asimov][id != 5][lang |= en]";
echo "** Select \"$query\":\n";
$nodes = CSSHelper::select($doc, $query);
foreach ($nodes as $node) {
echo CSSHelper::dom2str($node) . "\n~~~\n";
}
echo "\n\n";
// multiple selectors example
$query = "books .comedy[author_id = eduardo-mendoza], books .sci-fi:nth-child(2)";
echo "** Select \"$query\":\n";
$nodes = CSSHelper::select($doc, $query);
foreach ($nodes as $node) {
echo CSSHelper::dom2str($node) . "\n~~~\n";
}
echo "\n\n";
|