当前位置: 首页>>代码示例>>PHP>>正文


PHP XML::getElementsByTagName方法代码示例

本文整理汇总了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>';
    }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:31,代码来源:examples.php

示例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'] . '&nbsp;[<a href="' . $a['link'] . '">more</a>]' . '<br /><br /></div>';
}
// display info
echo $out;
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:31,代码来源:rss1.inc.php


注:本文中的XML::getElementsByTagName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。