php中dom生成的xml如何输出到页面上 dom xml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这是创建的xml,你得些一个程序读取xml1)DOMDocument读取xml<?php $doc = new DOMDocument(); $doc->load('person.xml'); //读取xml文件 $humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组 foreach( $humans as $human ) { $names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组 $name = $names->item(0)->nodeValue; //取得node中的值,如<name> </name> $sexs = $human->getElementsByTagName( "sex" ); $sex = $sexs->item(0)->nodeValue; $olds = $human->getElementsByTagName( "old" ); $old = $olds->item(0)->nodeValue; echo "$name - $sex - $old\n"; } ?> 2)simplexml读取xml<?php $xml_array=simplexml_load_file('person.xml'); //将XML中的数据,读取到数组对象中 foreach($xml_array as $tmp){ echo $tmp->name."-".$tmp->sex."-".$tmp->old."<br>"; } ?> 我这不是在读取一个xml,是从数据库读取数据并生成一个xml并显示在网页上,我在循环里如果写$dom->save('new_materials.xml');是可以正常生成xml的,可我是想显示在网页上,我用echo和print都不能实现 用echo和print都是可以的,但要保证没有其他输出。否则会因多了其他内容而造成浏览器解析失败最好还先发一个类型声明:header("Content-type: text/xml"); 设计一个log类,需要用到MySQL中的CURD操作,是应该使用继承呢还是组合?请给出理由 全国性的大站怎么搞?有经验的交流下 关于php以post方式传递参数问题 奇怪的session问题 PHP200人高级群:66589844 交流和学习者进 linux下修改模板失效 200分:贝宝收款做,安全要注意什么? 高手进,谢谢! Cannot encode non-existent session.怎么回事? 如何学习php,各位朋友给点意见... 大家来找茬 谁帮忙看看 这个代码为什么不会循环 PHP 代码 在下来框判断报错
$doc = new DOMDocument();
$doc->load('person.xml'); //读取xml文件
$humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组
foreach( $humans as $human )
{
$names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组
$name = $names->item(0)->nodeValue; //取得node中的值,如<name> </name>
$sexs = $human->getElementsByTagName( "sex" );
$sex = $sexs->item(0)->nodeValue;
$olds = $human->getElementsByTagName( "old" );
$old = $olds->item(0)->nodeValue;
echo "$name - $sex - $old\n";
}
?> 2)simplexml读取xml<?php
$xml_array=simplexml_load_file('person.xml'); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tmp){
echo $tmp->name."-".$tmp->sex."-".$tmp->old."<br>";
}
?>
否则会因多了其他内容而造成浏览器解析失败
最好还先发一个类型声明:
header("Content-type: text/xml");