A large number of smiplexml functions can be used to load and parse a large number of XML documents.
--------------------------------------------------------------------------------
1.
simplexml_load_file ()function to load the specified XML file into the object. Returns flase If a problem is encountered while loading the file. Cases:
Book.xml file:
Copy Code code as follows:
<?xml version= "1.0" standalone= "yes"?>
<library>
<book>
<title>pride and Prejudice</title>
<author gender= "female" >jane austen</author>
<description>jane Austen ' s most popular work.</description>
</book>
<book>
<title>the conformist</title>
<author gender= "Male" >alberto moravia</author>
<description>alberto Moravia ' s classic psyhcological novel.</description>
</book>
<book>
<title>the Sun Also rises</title>
<author gender= "Male" >ernest hemingway</author>
<description>the masterpiece that launched Hemingway ' s career.</description>
</book>
</library>
PHP File:
Copy Code code as follows:
<?php
$xml =simplexml_load_file ("Book.xml"); echo "<pre>";
Var_dump ($xml);
?>
Output results:
Copy Code code as follows:
Object (SimpleXMLElement) #1 (1) {
["Book"]=>
Array (3) {
[0]=>
Object (SimpleXMLElement) #2 (3) {
["title"]=>
String (Pride and Prejudice)
["Author"]=>
String (one) "Jane Austen"
["description"]=>
String (s) "Jane Austen ' most popular work."
}
[1]=>
Object (SimpleXMLElement) #3 (3) {
["title"]=>
String "The Conformist"
["Author"]=>
String (Alberto Moravia)
["description"]=>
String (s) "Alberto Moravia ' classic psyhcological novel."
}
[2]=>
Object (SimpleXMLElement) #4 (3) {
["title"]=>
String (a) "The Sun Also Rises"
["Author"]=>
String ("Ernest Hemingway")
["description"]=>
String ($) "The masterpiece that launched Hemingway ' s career."
}
}
}