PHPSimpleXML_PHP tutorial-php Tutorial

Source: Internet
Author: User
PHPSimpleXML. Compared with the DOM or Expat parser, SimpleXML can read text data from elements with just a few lines of code. SimpleXML can convert an XML document to an object. for example, compared with the DOM or Expat parser, SimpleXML can read text data from an element with just a few lines of code.

SimpleXML converts an XML document to an object.For example:

Element-a single attribute of the SimpleXMLElement object. When multiple elements exist at the same level, they are placed in an array.

Attribute-access by using an associated array. the subscript corresponds to the attribute name.

Element data-text data from an element is converted to a string. If an element has multiple text nodes, they are arranged in the order they are found.

SimpleXML is quick to use when you execute basic tasks similar to the following:

Read XML files

Extract data from XML strings

Edit a text node or attribute

However, when processing advanced XML, such as namespaces, it is best to use the Expat parser or xml dom.


SimpleXML functions are a core component of PHP. You can use these functions without installation.


XML file:

 
 
  
   George
  
  
   John
  
  
   Reminder
  Don't forget the meeting!
 


PHP:
 getName() . "
";foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "
"; }?>


Compared with the external DOM or Expat parser, SimpleXML can read text data from elements with just a few lines of code. SimpleXML can be used to convert an XML document to an object, for example, element-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.