解决方案 »

  1.   

    你这是创建的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>"; 

    ?> 
      

  2.   

    我这不是在读取一个xml,是从数据库读取数据并生成一个xml并显示在网页上,我在循环里如果写$dom->save('new_materials.xml');是可以正常生成xml的,可我是想显示在网页上,我用echo和print都不能实现
      

  3.   

    用echo和print都是可以的,但要保证没有其他输出。
    否则会因多了其他内容而造成浏览器解析失败
    最好还先发一个类型声明:
    header("Content-type: text/xml");