Detailed analysis of PHP5 object simplexml

Source: Internet
Author: User
Tags php website

Simplexml_load_file (str file); loads an xml file into a simplexml object. This method returns a handle.

Simplexml_load_string (str string); loads an xml file into a simplexml object. This method returns a handle.

Simplexml_import_dom (data) This function converts a dom node into a simplexml object, where data is a practical DOM node.

$ Simplexml-> addAttribute (name, value) adds an attribute to the simplexml object element. Note that it is a simplexml object element rather than a simplexml object handle.

$ Simplexml-> addChlid (name, value) adds a subnode to the specified XML Node

$ Simplexml-> asXML () returns an XML document in the form of a string from the SimpleXMLElement object, which can be used as an xml document for saving.

$ Simplexml-> attributes () returns an array composed of attributes of the simplexml Element Node of the PHP5 object,

Running the code above will print out an Array, Array ([@ attributes] => Array ([name] => cx, html [tt] => ddd ))

It can be seen that $ simplexml-> attributes () obtains all attributes of an xml Element Node, but is contained in an [@ attributes] array, therefore, you must use $ xml = $ xml ['@ bubutes'] to obtain

$ Simplexml-> Children () returns an array composed of Children of simplexml object element nodes.

$ Simplexml->__ construct () to create a new XML document

$ Simplexml-> getDocNamespaces () This function returns the $ simplexml object-defined namespace

$ Simplexml-> getName () returns the name of the $ simplexml object element, that is, the tag name.

$ 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

Instance 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 the fun of PHP website development and construction, and teach you how to build a website</Description> 
  7. <Bloger>David</Bloger> 
  8. <Date>2009-05-</Date> 
  9. <Qq>QQ: 154130270</Qq> 
  10. </LeapsoulInfo> 
  11.  
  12. <LeapsoulInfo>
  13. <Name>Leapsoul-PHP website development</Name> 
  14. <Website>Http://www.leapsoul.cn</Website> 
  15. <Description>Share the fun of PHP website development and construction, and teach you how to build a website</Description> 
  16. <Bloger>David</Bloger> 
  17. <Date>2009-05-13</Date> 
  18. <Qq>QQ: 154130270</Qq> 
  19. </LeapsoulInfo> 
  20. </LeapsoulXML> 

We can combine the preceding example of the PHP5 object simplexml with our own understanding. We should be able to fully understand this newly added function.


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.