This article provides a detailed analysis of XML operations in PHP. For more information, see
$ Xml = simplexml_load_file ('example. XML'); // Create a SimpleXML object
Var_dump ($ xml); // output XML
?>
$ 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
}
?>
$ Xml = simplexml_load_file ('example. XML'); // read the xml file
Echo $ xml-> depart-> name [0]; // output node
?>
$ 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
}
?>
$ 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
?>
$ Xml = simplexml_load_file ('example. XML'); // read xml
$ Xml-> depart-> name [0] = "Human Resource"; // modify a node
?>
$ Xml = simplexml_load_file ('example. XML'); // read xml data
Echo $ xml-> asXML (); // standardize 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); // close the file
?>