php 读取xml

  作者:会飞的

<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"

<?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
";


  }


  ?>