本文整理汇总了PHP中XML::getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:PHP XML::getElementsByTagName方法的具体用法?PHP XML::getElementsByTagName怎么用?PHP XML::getElementsByTagName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML
的用法示例。
在下文中一共展示了XML::getElementsByTagName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isset
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>';
}
示例2: asArray
<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'] . ' [<a href="' . $a['link'] . '">more</a>]' . '<br /><br /></div>';
}
// display info
echo $out;