PHP5 object simplexml detailed analysis _ PHP Tutorial

Source: Internet
Author: User
A detailed analysis of the PHP5 object simplexml. Simplexml_load_file (strfile); loads an xml file into a simplexml object. this method returns a handle simplexml_load_string (strstring); loads an xml file into a simpleSimplexml_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-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 the fun of PHP website development and construction, 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 preceding example of the PHP5 object simplexml with our own understanding. we should be able to fully understand this newly added function.


Http://www.bkjia.com/PHPjc/446334.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446334.htmlTechArticlesimplexml_load_file (str file); loads an xml document into a simplexml object, which returns a handle simplexml_load_string (str string); loads an xml document into a simple...

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.