Ejemplo n.º 1
0
	being a useful example base, it also serves as a unit test system for the functionality of
	<span class="name">phpdomxml</span>. Please pick a test batch to run from the list below.
	</p>

<?php 
// phpdomxml test/example suite
// (ps: I realise it's kinda awkward to use xml dom-methods in a
// test-suite for exactly that, but fortunately the methods I use
// below have already been tested thorougly before I made this.)
// get batch to run
$getbatch = isset($_GET['batch']) ? $_GET['batch'] : null;
// include lib and get test batches from xml file
include_once '../lib.xml.inc.php';
$xml = new XML('tests.xml');
// get list of batches
$batches = $xml->getElementsByTagName('batch');
// loop through all batches and list some info
$i = 1;
$s = '<p>';
foreach ($batches as $batch) {
    $id = $batch->getAttribute('id');
    $title = $batch->firstChild->firstChild->data;
    $nrtests = count($batch->getElementsByTagName('test'));
    $pl = $nrtests > 1;
    if ($id == $getbatch) {
        $s .= '<b>';
    }
    $s .= $i++ . '. <a href="' . $_SERVER['PHP_SELF'] . '?batch=' . $id . '">' . $title . '</a>' . ' (' . $nrtests . ' test' . ($pl ? 's' : '') . ')<br />';
    if ($id == $getbatch) {
        $s .= '</b>';
    }
Ejemplo n.º 2
0
<script type="text/javascript">
	function dspSwitch(id) {
		var d = document.getElementById(id).style;
		d.display = (d.display == 'block')?'none':'block';
	}
</script>
<?php 
// include xml lib
include_once '../lib.xml.inc.php';
// convert an rdf item to an associative array
function asArray($item)
{
    $a = array();
    while ($item) {
        $a[$item->nodeName] = $item->firstChild->nodeValue;
        $item = $item->nextSibling;
    }
    return $a;
}
// get the feed
$rdf = new XML('http://slashdot.org/index.rss');
// get article items
$items = $rdf->getElementsByTagName('item');
// loop and gather info
$out = '';
foreach ($items as $k => $item) {
    $a = asArray($item->firstChild);
    $out .= '<a href="javascript:;" ' . 'onclick="dspSwitch(\'item' . $k . '\')">' . $a['title'] . '</a> (' . $a['dc:date'] . ')<br />' . '<div id="item' . $k . '" style="display:none">' . $a['description'] . '&nbsp;[<a href="' . $a['link'] . '">more</a>]' . '<br /><br /></div>';
}
// display info
echo $out;