Home  >  Article  >  Backend Development  >  Explore how to use SimpleXML functions to load and parse XML documents_PHP Tutorial

Explore how to use SimpleXML functions to load and parse XML documents_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:08:13972browse

A number of SmipleXML functions are available for loading and parsing large XML documents.
-------------------------------------------------- ----------------------------------
1.simpleXML_load_file() Function to load the specified XML file into the object. Returns FLASE if there is a problem loading the file. Example:
book.xml file:

Copy code The code is as follows:




Pride and Prejudice
Jane Austen
Jane Austen's most popular work.


The Conformist</ title><br> <author gender="male">Alberto Moravia</author><br> <description>Alberto Moravia's classic psyhcological novel.</description><br> </book><br> <book><br> <title>The Sun Also Rises
Ernest Hemingway
The masterpiece that launched Hemingway's career.



php file:
Copy code The code is as follows:

$xml=simplexml_load_file("book.xml");echo "
";
var_dump($ xml);
?>

Output result:
Copy code 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) {
                                                                                                                                                                            description"]=>
string(46) "Alberto 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."
}
}
}





http://www.bkjia.com/PHPjc/327494.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/327494.htmlTechArticleA large number of SmipleXML functions can be used to load and parse large amounts of XML documents. -------------------------------------------------- ----------------------------- 1. simpleXML_load_file() function to load...
Statement:
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