This article provides a detailed analysis of the use of SimpleXML functions to load and parse XML documents. For more information, see a large number of SmipleXML functions.
--------------------------------------------------------------------------------
1.
SimpleXML_load_file ()Function to load the specified XML file to the object. If a problem occurs during File loading, FLASE is returned. Example:
Book. xml file:
The code is as follows:
Pride and Prejudice
Jane Austen
Jane Austen's most popular work.
The Conformist
Alberta Moravia
Alberta Moravia's classic psyhcological novel.
The Sun Also Rises
Ernest Hemingway
The masterpiece that launched Hemingway's career.
Php file:
The code is as follows:
$ Xml = simplexml_load_file ("book. xml"); echo"
";
Var_dump ($ xml );
?>
Output result:
The code is as follows:
Object (SimpleXMLElement) #1 (1 ){
["Book"] =>
Array (3 ){
[0] =>
Object (SimpleXMLElement) #2 (3 ){
["Title"] =>
String (19) "Pride and Prejudice"
["Author"] =>
String (11) "Jane Austen"
["Description"] =>
String (32) "Jane Austen's most popular work ."
}
[1] =>
Object (SimpleXMLElement) #3 (3 ){
["Title"] =>
String (14) "The Conformist"
["Author"] =>
String (15) "Albert to Moravia"
["Description"] =>
String (46) "Albert to Moravia's classic psyhcological novel ."
}
[2] =>
Object (SimpleXMLElement) #4 (3 ){
["Title"] =>
String (18) "The Sun Also Rises"
["Author"] =>
String (16) "Ernest Hemingway"
["Description"] =>
String (49) "The masterpiece that launched Hemingway's career ."
}
}
}