Explore how to use the SimpleXML function to load and parse XML documents _php Tutorial

Source: Internet
Author: User
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. If you are having trouble loading the file, return flase. Cases:
Book.xml file:
Copy CodeThe code is as follows:



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


The Conformist
Alberto Moravia
Alberto Moravia ' s classic psyhcological novel.


The Sun Also rises
Ernest Hemingway
The masterpiece that launched Hemingway ' s career.



PHP Files:
Copy CodeThe code is as follows:
$xml =simplexml_load_file ("Book.xml"); echo "
";
Var_dump ($xml);
?>

Output Result:
Copy CodeThe code is 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 (+) "Jane Austen ' s most popular work."
}
[1]=>
Object (SimpleXMLElement) #3 (3) {
["title"]=>
String ("The Conformist")
["Author"]=>
String ("Alberto Moravia")
["description"]=>
String "Alberto Moravia's classic psyhcological novel."
}
[2]=>
Object (SimpleXMLElement) #4 (3) {
["title"]=>
String ("The Sun Also Rises")
["Author"]=>
String (+) "Ernest Hemingway"
["description"]=>
String "The masterpiece that launched Hemingway ' s career."
}
}
}

http://www.bkjia.com/PHPjc/327494.html www.bkjia.com true http://www.bkjia.com/PHPjc/327494.html techarticle 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 ...

  • 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.