<? 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
?>