一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php domdocument 解析xml文档实例

时间:2022-06-24 20:53:56 编辑:袖梨 来源:一聚教程网

//解析xml实例一
$objDOM = new DOMDocument();
$objDOM->load("xml.xml");
$parent = $objDOM->getElementsByTagName("Product");
foreach( $parent as $value )
  {
    $names = $value->getElementsByTagName("Name");
    $name  = $names->item(0)->nodeValue;
   
    $urls = $value->getElementsByTagName("Url");
    $url  = $urls->item(0)->nodeValue;
   
    $images = $value->getElementsByTagName("Image");
    $image  = $images->item(1)->nodeValue;
  }
 
 //DOMDocument实例二
 
$xml = new DOMDocument();
$xml->load("me.xml");
$postDom = $xml->getElementsByTagName("post");
foreach($postDom as $post){
$title = $post->getElementsByTagName("title");
echo "Id: " . $title->item(0)->attributes->item(0)->nodeValue . "
";
echo "Title: " . $title->item(0)->nodeValue . "
";
echo "Details: " . $post->getElementsByTagName("details")->item(0)->nodeValue . "

";
}
 
?>
xml.xml

       
               
                        网页制作教程教程
                       
                                Small
                                http://www.111com.net
                       
                       
                                Medium
                                http://www.111com.net
                       
                       
                                Large
                                http://www.111com.net
                       
               

       


me.xm;




PHP XML处理介绍一

详细内容一



PHP XML处理介绍二
详细内容二



PHP XML处理介绍三
详细内容三


热门栏目