最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 解析XML DOMXPath的例子
时间:2022-11-14 23:00:16 编辑:袖梨 来源:一聚教程网
xml文件结构如下
php代码解析:
$url="";//输出xml的URL $dom = new DOMDocument('1.0', 'utf-8'); $dom->load($url);
这样我们捕获里XML数据,然后一点点截取,这段XML有多个URL节点,需要利DOMPATH解析
$xpath = new DOMXPath($dom); $node = '//url'; $length = $xpath->query($node)->length;
然后根据每个url内的字节点去获取数据
for($i = 0; $i < $length; $i++) { $data = array(); $m_date = date('Y-m-d', strtotime($xpath->query($node.'['.($i+1).']/date')->item(0)->nodeValue)); $m_start = $xpath->query($node.'['.($i+1).']/start')->item(0)->nodeValue; $m_end = $xpath->query($node.'['.($i+1).']/end')->item(0)->nodeValue; $m_title = $xpath->query($node.'['.($i+1).']/title')->item(0)->nodeValue; $m_format = $xpath->query($node.'['.($i+1).']/format')->item(0)->nodeValue; $m_season = $xpath->query($node.'['.($i+1).']/season')->item(0)->nodeValue; $m_round = $xpath->query($node.'['.($i+1).']/round')->item(0)->nodeValue; /*$homeTeam = $xpath->query($node.'['.($i+1).']/homeTeam')->item(0)->nodeValue; if(empty($homeTeam)) continue; $guestTeam = $xpath->query($node.'['.($i+1).']/guestTeam')->item(0)->nodeValue; if(empty($guestTeam)) continue;*/ $homeTeam = $xpath->query($node.'['.($i+1).']/homeTeam')->item(0)->nodeValue; $guestTeam = $xpath->query($node.'['.($i+1).']/guestTeam')->item(0)->nodeValue; if(empty($guestTeam) || empty($homeTeam)) { if($m_title){ $temp_title=explode(" ", $m_title); list($homeTeam,$guestTeam)=explode("vs", $temp_title[1]); unset($temp_title); } } if(empty($homeTeam)) continue; if(empty($guestTeam)) continue; }
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20