PHP simplexml_php Tutorials

Source: Internet
Author: User
Compared to DOM or Expat parsers, SimpleXML can read text data from elements in just a few lines of code.

SimpleXML can convert XML documents to objects , 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

However, when working with advanced XML, such as namespaces, it is best to use the Expat parser or the XML DOM.


The SimpleXML function is part of the PHP core. These functions can be used without installation.


XML file:

 
  
 
  
  
   
    
   George
  
   
  
   
    
   John
  
   
  
   
    
   Reminder
  
   Don ' t forget the meeting!
 
  


Php:
 
  GetName (). "
"; foreach ($xml->children () as $child) { echo $child->getname ().": ". $child. "
"; }? >


http://www.bkjia.com/PHPjc/755781.html www.bkjia.com true http://www.bkjia.com/PHPjc/755781.html techarticle compared to DOM or Expat parsers, SimpleXML can read text data from elements in just a few lines of code. SimpleXML can convert an XML document to an object, such as an element-to be converted ...

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