If you want to create SimpleXML objects and learn how to operate xml, see. Example. xml file:
The code is as follows:
$ Xml = simplexml_load_file ('example. XML'); // Create a SimpleXML object
Print_r ($ xml); // output XML
?>
The code is as follows:
Production support
100001
Simon
24
1982-11-06
5000.00
1000.00
100002
Eline
24
1982-01-01
6000.00
2000.00
Testing center
110001
Helen
23
1983-07-21
5000.00
1000.00
The code is as follows:
$ Xml = simplexml_load_file ('example. XML'); // Create a SimpleXML object
Var_dump ($ xml); // output XML
?>
The code is as follows:
$ 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
"; // Output the name attribute
}
?>
The code is as follows:
$ Xml = simplexml_load_file ('example. XML'); // read the xml file
Echo $ xml-> depart-> name [0]; // output node
?>
The code is as follows:
$ 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
}
?>
The code is as follows:
$ 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
?>
The code is as follows:
$ Xml = simplexml_load_file ('example. XML'); // read xml
$ Xml-> depart-> name [0] = "Human Resource"; // modify a node
?>
The code is as follows:
$ Xml = simplexml_load_file ('example. XML'); // read xml data
Echo $ xml-> asXML (); // standardize XML data
?>
The code is as follows:
$ 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
?>