<? PHP
$ Xml = simplexml_load_file ('example. xml'); // create a simplexml object
Var_dump ($ XML); // output XML
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml'); // read the XML file
Foreach ($ XML-> depart as $ A) // read each depart tag in XML data cyclically
{
Echo "$ A-> name <br>"; // output the name attribute.
}
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml'); // read the XML file
Echo $ XML-> depart-> name [0]; // output Node
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml ');
Foreach ($ XML-> depart-> Children () as $ depart) // read sub-tags under the depart tag cyclically
{
Var_dump ($ depart); // output the XML data of the tag
}
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml'); // read the XML file
$ Result = $ XML-> XPath ('/departs/depart/employees/employee/name'); // define a node
Var_dump ($ result); // output Node
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml'); // read XML
$ XML-> depart-> name [0] = "human resource"; // modify a node
?>
<? PHP
$ Xml = simplexml_load_file ('example. xml'); // read XML data
Echo $ XML-> asxml (); // standardize XML data
?>
<? PHP
$ 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); // close the file
?>