本文实例讲述了php基于dom实现读取图书xml格式数据的方法。分享给大家供大家参考,具体如下:
| 代码如下 | 复制代码 |
<?php $doc=newDOMDocument(); $doc->load('books.xml'); $books=$doc->getElementsByTagName("book"); foreach($booksas$book) { $authors=$book->getElementsByTagName("author"); $author=$authors->item(0)->nodeValue; $publishers=$book->getElementsByTagName("publisher"); $publisher=$publishers->item(0)->nodeValue; $titles=$book->getElementsByTagName("title"); $title=$titles->item(0)->nodeValue; echo"$title - $author - $publishern"; } ?> | |
books.xml文件如下:
| 代码如下 | 复制代码 |
<?xmlversion="1.0"?>
Jack Herrington PHP Hacks O'Reilly
Jack Herrington Podcasting Hacks O'Reilly
| |
运行结果如下:
PHP Hacks - Jack Herrington - O'Reilly
Podcasting Hacks - Jack Herrington - O'Reilly
韩剧再婚皇后阿里云盘全集高清1080P资源链接-韩剧再婚皇后免费阿里云盘资源下载4K高清无删减版链接
poipiku网站如何打开-poipiku官网网页版访问入口
明日方舟:终末地-云游戏畅玩入口-明日方舟:终末地-网页版在线直连地址
poki在线小游戏网页版-poki免费游戏大全入口
poki游戏入口-点开即玩-poki游戏-在线免费畅玩
原神akt大佬资源viciNeko入口链接-原神akt大佬资源网页vicineko入口链接分享