Php 解析XML文件

Php 解析XML文件,仅供学习參考!演示样例代码例如以下:

<?php
header("Content-type: text/html; charset=utf-8");
if(!isset($_GET["_u"])){
echo "<script>javascript:alert('请勿非法訪问!');window.history.back();</script>";
exit();
} $url = $_GET["_u"];
?>
<table width="100%" height="auto" cellpadding="0" cellspacing="0">
<tbody>
<?php
//创建Document对象
$doc = new DOMDocument();
$doc -> load($url); $news = $doc -> getElementsByTagName("item"); $title = "";$date = "";$detail = "";
$len = ($news -> length);$model = null; if($len > 0){
//遍历子节点
for ($i=0; $i < $len; $i++) {
$model = $news -> item($i);
$title = $model -> getElementsByTagName("title") -> item(0) -> nodeValue;
$date = $model -> getElementsByTagName("pubDate") -> item(0) -> nodeValue;
$detail = $model -> getElementsByTagName("content") -> item(0) -> nodeValue;
?>
<tr>
<th>
<a href="javascript:void(0);"><?php echo($title) ?></a>
<a href="javascript:void(0);"><img alt="" src="/images/Plus.jpg" title="展开" /></a>
</th>
<th>
<?php echo($date) ?>
</th>
</tr>
<tr style="display:none;">
<th colspan="2">
<?php echo($detail) ?>
</th>
</tr>
<?php
}
}else{
//没有内容
?>
<tr>
<th colspan="2">
<b><font color="red">临时没有内容显示!</font></b>
</th>
</tr>
<?php
}
?>
</tbody>
</table>

效果图例如以下:

Php 解析XML文件的更多相关文章

  1. Android 解析XML文件和生成XML文件

    解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...

  2. JAVA使用SAX解析XML文件

    在我的另一篇文章(http://www.cnblogs.com/anivia/p/5849712.html)中,通过一个例子介绍了使用DOM来解析XML文件,那么本篇文章通过相同的XML文件介绍如何使 ...

  3. JAVA中使用DOM解析XML文件

    XML是一种方便快捷高效的数据保存传输的格式,在JSON广泛使用之前,XML是服务器和客户端之间数据传输的主要方式.因此,需要使用各种方式,解析服务器传送过来的信息,以供使用者查看. JAVA作为一种 ...

  4. java中采用dom4j解析xml文件

    一.前言 在最近的开发中用到了dom4j来解析xml文件,以前听说过来解析xml文件的几种标准方式:但是从来的没有应用过来,所以可以在google中搜索dmo4j解析xml文件的方式,学习一下dom4 ...

  5. XML:使用DOM技术解析xML文件中的城市,实现select级联选择

    中国的城市xml格式:cities.xml <?xml version="1.0" encoding="utf-8"?> <china> ...

  6. dom4j如何解析XML文件

    最近在 一些对xml文件的操作,下面简单写一个dom4j解析xml文件并将其封装到一个javabean中的例子,只是具有针对性的,不是通用的,仅供参考哦~~ 首先说:dom4j是一个java的XML ...

  7. java解析XML文件

    dom4j是一个Java的XML API,类似于jdom,用来读写XML文件的.dom4j是一个非常非常优秀的Java XML API,具有性能优异.功能强大和极端易用使用的特点,同时它也是一个开放源 ...

  8. Android开发学习---使用XmlPullParser解析xml文件

    Android中解析XML的方式主要有三种:sax,dom和pull关于其内容可参考:http://blog.csdn.net/liuhe688/article/details/6415593 本文将 ...

  9. SAX解析xml文件

    需要做一个银行名字的列表. 因为有很多,所以想到了用xml来保存,然后uongDAX解析. public class BankSelectActivity extends BaseActivity{ ...

  10. 使用dom4j创建和解析xml文件

    使用dom4j创建和解析xml文件 在项目开发中,我们经常会遇到xml文件的创建和解析从别人接口得到的xml文件,而我们最常使用的组件是dom4j. 下面我就以代码来讲解一下如何使用dom4j来创建x ...

随机推荐

  1. 获取sdcard和内存的存储空间

    package com.example.sdcardspace; import java.io.File; import android.os.Bundle; import android.os.En ...

  2. ACM比赛(11462 Age Sort)

    You are given the ages (in years) of all people of a country with at least 1 year of age. You know t ...

  3. js中with、this的用法

    with 语句 为一个或一组语句指定默认对象. 用法:with (<对象>) <语句>; with 语句通常用来缩短特定情形下必须写的代码量.在下面的例子中,请注意 Math ...

  4. mac忘记登陆密码解决

    重新启动苹果电脑,开机时按住“command”键+“S”键,(普通键盘按住win+s)会进入单用户模式, 出现像DOS一样的提示符 #root>依次输入如下三个命令:(注意空格 注意大小写) f ...

  5. 读书笔记:php_tizag_tutorial

    昨天在实验室花了一天时间看了英文版的php_tizag_tutorial,因为上学期用php和bootstrap写过一个租房网站,对php还是比较熟悉.现在总结一下php_tizag_tutorial ...

  6. mysql basic operation,mysql总结

    mysql> select * from wifi_data where dev_id like "0023-AABBCCCCBBAA" ; 1.显示数据库列表.show d ...

  7. C++学习笔记(十二):重载函数

    1. 什么是重载函数 假设同一作用域内的几个函数名字同样但形參列表不同.那么这些函数就称之为--重载函数. 比如: void print( const char *cp); void print(co ...

  8. sql: sql developer tunnel转接

    Use putty tunnel instead of login terminal server 有时候本地直接ping不通sql 的server, 但另一个server能连上,这时就可以把端口和i ...

  9. C语言,const

    const意味着“只读” ubunto下的实验 1). 关键字const的作用是为给读你代码的人传达非常有用的信息,实际上,声明一个参数为常量是为了告诉了用户这个参数的应用目的.如果你曾花很多时间清理 ...

  10. 托管到GitHub

    如何把项目托管到GitHub iOS开发拓展篇——如何把项目托管到GitHub 说明:本文主要介绍如何把一个OC项目托管到Github,重操作轻理论. 第一步:先注册一个Github的账号,这是必须的 ...