Detailed explanation of XML operations based on PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:07:44
Original
720 people have browsed it

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

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

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

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

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

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

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

$xml = simplexml_load_file('example.xml'); //Read XML data
$newxml = $xml->asXML(); 🎜 > $fp = fopen("newxml.xml", "w"); //Open the file to write XML data to fclose( $fp); 



http://www.bkjia.com/PHPjc/327509.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/327509.htmlTechArticle?php $xml = simplexml_load_file('example.xml'); //Create SimpleXML object var_dump($xml) ; //Output XML ? ?php $xml = simplexml_load_file('example.xml'); //Read XML file foreach($xml...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!