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

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. 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."
}
}
}

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.