无为清净楼资源网 Design By www.qnjia.com

<?php 

    $xml = simplexml_load_file('example.xml');              //创建SimpleXML对象  
    var_dump($xml);                                                             //输出XML  
?> 

<?php 
    $xml = simplexml_load_file('example.xml');          //读取XML文件  
    foreach($xml->depart as $a)                                    //循环读取XML数据中的每一个depart标签  
    { 
        echo "$a->name <BR>";                                       //输出其中的name属性  
    } 
?> 

<?php 
    $xml = simplexml_load_file('example.xml');          //读取XML文件  
    echo $xml->depart->name[0];                                  //输出节点  
?> 

<?php 
    $xml = simplexml_load_file('example.xml'); 
    foreach ($xml->depart->children() as $depart)             //循环读取depart标签下的子标签  
    { 
       var_dump($depart);                                                        //输出标签的XML数据  
    } 
?> 

<?php 
    $xml = simplexml_load_file('example.xml');                      //读取XML文件  
    $result = $xml->xpath('/departs/depart/employees/employee/name');        //定义节点  
    var_dump($result);                                          //输出节点  
?> 

<?php 
    $xml = simplexml_load_file('example.xml');              //读取XML  
    $xml->depart->name[0] = "Human Resource";         //修改节点  
?> 

<?php 
    $xml = simplexml_load_file('example.xml');              //读取XML数据  
    echo $xml->asXML();                                                     //标准化XML数据  
?> 

<?php 
    $xml = simplexml_load_file('example.xml');              //读取XML数据  
    $newxml = $xml->asXML();                         //标准化XML数据  
    $fp = fopen("newxml.xml", "w");                  //打开要写入XML数据的文件  
    fwrite($fp, $newxml);                                    //写入XML数据  
    fclose($fp);                                                     //关闭文件  
?> 

标签:
php操作xml

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com