最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
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
me.xm;
相关文章
- 炉石传说血DK卡组怎么样 炉石传说血DK卡组推荐介绍 11-05
- 咒术回战幻影夜行官网在哪里 咒术回战幻影夜行官网地址介绍 11-05
- 蚂蚁庄园今天答题答案2024年10月26日 11-05
- 以闪亮之名变装物语甜趣篇怎么玩 11-05
- 闪耀暖暖永夜禁锢怎么玩 11-05
- 闪耀暖暖永夜禁锢怎么玩 闪耀暖暖永夜禁锢活动介绍 11-05