Detailed analysis of PHP5 object SimpleXML _php Tutorial

Source: Internet
Author: User
Tags php website
Simplexml_load_file (str file); Loads an XML document into a SimpleXML object, and this method returns a handle

Simplexml_load_string (str string); Loads an XML document into a SimpleXML object that returns a handle

Simplexml_import_dom (data) This function converts a DOM node to a SimpleXML object, where data is a useful DOM node

$simplexml->addattribute (name,value) adds a property to the SimpleXML object element, note that it is a SimpleXML object element, not a SimpleXML object handle.

$simplexml->addchlid (name,value) adds a child node to the specified XML node

$simplexml->asxml () returns an XML document from a SimpleXMLElement object as a string, which can be used as an XML document to save

$simplexml->attributes () returns an array of the properties of the SimpleXML element node of the PHP5 object.

Run the above code to print out the array ([@attributes] = = Array ([name] = cx,html [tt] = DDD))

As you can see, $simplexml->attributes () gets all the attributes of an XML element node, but is contained in a [@attributes] array, so it is obtained by $xml = $xml [' @attributes '].

$simplexml->children () returns an array of children of the SimpleXML object element node

$simplexml->__construct () to create a new XML document

$simplexml->getdocnamespaces () This function returns the namespace defined by the $simplexml object

$simplexml->getname () returns the name of the $simplexml object element, which is the label signature

$simplexml->getnamespaces () returns the namespace used by the $simplexml object

$simplexml->registerxpathnamespace () This function creates a namespace context for the next XPath query

$simplexml->xpath () uses the XPath syntax to parse a PHP5 object simplexml

Example code 1

 
 
  1. xml version="1.0 " encoding= "GBK"?>
  2. < Leapsoulxml >
  3. < Leapsoulinfo >
  4. < name > leapsoul-php Website Development name>
  5. < website > http://www.leapsoul.cn website>
  6. < Description > Share PHP website development and building fun and teach you how to build a website description>
  7. < Bloger > David bloger>
  8. < Date > 2009-05-13 date>
  9. < QQ > qq:154130270 qq>
  10. leapsoulinfo>
  11. < Leapsoulinfo >
  12. < name > leapsoul-php Website Development name>
  13. < website > http://www.leapsoul.cn website>
  14. < Description > Share PHP website development and building fun and teach you how to build a website description>
  15. < Bloger > David bloger>
  16. < Date > 2009-05-13 date>
  17. < QQ > qq:154130270 qq>
  18. leapsoulinfo>
  19. leapsoulxml>

We can combine the above PHP5 object SimpleXML example, plus our own understanding, should be able to fully understand this new function.


http://www.bkjia.com/PHPjc/446334.html www.bkjia.com true http://www.bkjia.com/PHPjc/446334.html techarticle simplexml_load_file (str file); Loads an XML document into a SimpleXML object, which returns a handle simplexml_load_string (str string); Load an XML document into a simple ...

  • Related Article

    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.