Home  >  Article  >  Backend Development  >  Detailed explanation of XML operations based on PHP

Detailed explanation of XML operations based on PHP

高洛峰
高洛峰Original
2016-12-24 11:24:591595browse

$xml = simplexml_load_file('example.xml'); //Create SimpleXML object
var_dump($xml); // Output XML
?>

$xml = simplexml_load_file ('example.xml');                                                                                                                                                                                                 echo "$a-> name
";                                                                                                                                                                                                                                                                                       ​ //Read XML file
echo $xml- >depart->name[0]; ml->depart-> children() as $depart)                                                                                                                                                                    . XML data
}
?>

$xml = simplexml_load_file('example.xml'); //Read XML file

$result = $xml->xpath('/departs/depart/employees/employee/name'); //Define nodes
var_dump($result ) ; 
$xml->depart->name[0] = "Human Resource"; " //Standardization XML data
?>

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

For more detailed explanations of XML operations based on PHP, please pay attention to the PHP Chinese website!

Statement:
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