php 读取xml
作者:会飞的
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://www.xinge360.com/</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>http://www.xinge360.com/login/login.asp</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.80</priority>
</url>
<url>
<loc>http://www.xinge360.com/login/register.asp</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.64</priority>
</url>
<url>
<loc>http://www.xinge360.com/accounts/get_password.asp</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.64</priority>
</url>
<url>
<loc>http://www.xinge360.com/index_sendfriend.asp</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.64</priority>
</url>
<url>
<loc>http://www.xinge360.com/linkurl/</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.64</priority>
</url>
<url>
<loc>http://www.xinge360.com/sitemap.html</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.64</priority>
</url>
<url>
<loc>http://www.xinge360.com/login/term.asp</loc>
<lastmod>2010-11-13T09:36:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.51</priority>
</url>
</urlset>
<?php
$doc = new DOMDocument();
$doc->load( 'test.xml' );
$urls = $doc->getElementsByTagName( "url" );
foreach( $urls as $url )
{
$locs = $url->getElementsByTagName( "loc" );
$loc = $locs->item(0)->nodeValue;
$lastmods = $url->getElementsByTagName( "lastmod" );
$lastmod = $lastmods->item(0)->nodeValue;
$changefreqs = $url->getElementsByTagName( "changefreq" );
$changefreq = $changefreqs->item(0)->nodeValue;
$prioritys = $url->getElementsByTagName( "priority" );
$priority = $prioritys->item(0)->nodeValue;
echo "网址:$loc - 时间$lastmod - 周$changefreq
";
}
?>
猜你喜欢
您可能感兴趣的文章:
- MySQL 性能优化技巧
- 生产环境CPU过高问题定位
- Linux netstat常用命令
- TCP连接数过多问题
- mysql 获取最后一条id
- killall命令杀死所有进程
- 使用ab进行页面的压力测试
- 解决centos yum安装
- Ansible
- php 利用array_slice函数获取随机数组或前几条数据
- PHP 换行
- ISSET()、empty()、is_numeric()的使用方法
- 排序算法
- 40个技巧优化您的PHP代码
- 40个迹象表明你还是PHP菜鸟
- Access to the requested object is only available from the local network.
- ob_get_contents() 函数的用法
- PHP OOP思想
- PHP XML Expat 解析器