Some simple examples of php operating xml files
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:59:07
Original
950 people have browsed it
-
-
/** - * php operation xml file
- * edit bbs.it-home.org
- */
- //Example 1
- $xml = simplexml_load_file('example.xml'); //Create SimpleXML object
- var_dump($ xml); //Output XML
//Example 2
- $xml = simplexml_load_file('example.xml'); //Read XML file
- foreach($xml->depart as $ a) //Loop through each part tag in the XML data
- {
- echo "$a->name
"; //Output the name attribute
- }
$xml = simplexml_load_file('example.xml'); //Read XML file - echo $xml->depart->name[0]; //Output node
-
//Example 4
- $xml = simplexml_load_file('example.xml');
- foreach ($xml->depart->children() as $depart) //Loop to read the children under the depart tag Tag
- {
- var_dump($depart); //Output the XML data of the tag
- }
//Example 5
- $xml = simplexml_load_file('example.xml'); //Read XML file
- $result = $xml->xpath('/departs/depart/employees/employee/name'); //Define node
- var_dump($result); //Output node
- < p>//Example 6
- $xml = simplexml_load_file('example.xml'); //Read XML
- $xml->depart->name[0] = "Human Resource"; //Modify node< /p>
//Example 7
- $xml = simplexml_load_file('example.xml'); //Read XML data
- echo $xml->asXML(); //Standardized XML data p>
//Example 8
- $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
- ?>
-
Copy code
|
Statement of this Website
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
Latest Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11