PHP Parsing xml_php Tutorial

Source: Internet
Author: User
1, SimpleXML


SimpleXML Convert an XML document to an object, such as:
Element-is converted to a single attribute of the SimpleXMLElement object. When multiple elements exist at the same level, they are placed in the array.
Property-accessed by using an associative array, where the subscript corresponds to the property name.
element data-text data from an element is converted to a string. If an element has more than one text node, it is arranged in the order in which they are found.
SimpleXML is very quick to use when performing basic tasks like the following:
Reading an XML file
Extracting data from an XML string
Edit a text node or property


 XML version= "1.0" encoding= "Utf-8"?> 
   
    
    php XML processing Introduction one </    
   title> <details> Details One </details> </post> <post> <title id= "2" >php XML processing Introduction two     
  
    
      details two 
     
     
 
    
    php XML processing introduction three  
    
      details three 
     
    
   !--? XML version= "1.0" encoding= "Utf-8"?--"
   
    
    php XML processing Introduction one  
    
      details a  
    
    
    
    php XML processing Introduction Two  
    
      details two   
      
      php XML processing introduction three  
      
        details three 
       
       attributes () Get Properties 
    
   
  
PHP    /**   * Load XML file   *    /$xml = simplexml_load_file ("Text.xml");    /**   * If the XML is a string, you can use the following method, followed by the same method   * $xml = simplexml_load_string */    /**   * Traversal $xml Object *   *    foreach ($xml as $key = + $value) {    //get property     $attr = $value->title->attributes ();    echo "Id:". $attr [' id ']. "
"; echo "Title:". $value->title. "
"; echo "Details:". $value->details . "

"; } ? > $value) { //get property $attr = $value->title->attributes (); echo "Id:". $attr [' id ']. "
"; echo "Title:". $value->title. "
"; echo "Details:". $value->details. "

"; } ? >

http://www.bkjia.com/PHPjc/477236.html www.bkjia.com true http://www.bkjia.com/PHPjc/477236.html techarticle 1. SimpleXML simplexml converts an XML document into an object, such as an element-a single attribute that is converted to a SimpleXMLElement object. When there are multiple elements at the same level, they are ...

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