Explore how to use SimpleXML functions to load and parse XML documents

Source: Internet
Author: User
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 ."
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.