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
- <?Xml Version="1.0" Encoding="Gbk"?>
- <LeapsoulXML>
- <LeapsoulInfo>
- <Name>Leapsoul-PHP website development</Name>
- <Website>Http://www.leapsoul.cn</Website>
- <Description>Share the fun of PHP website development and construction, and teach you how to build a website</Description>
- <Bloger>David</Bloger>
- <Date>2009-05-</Date>
- <Qq>QQ: 154130270</Qq>
- </LeapsoulInfo>
-
- <LeapsoulInfo>
- <Name>Leapsoul-PHP website development</Name>
- <Website>Http://www.leapsoul.cn</Website>
- <Description>Share the fun of PHP website development and construction, and teach you how to build a website</Description>
- <Bloger>David</Bloger>
- <Date>2009-05-13</Date>
- <Qq>QQ: 154130270</Qq>
- </LeapsoulInfo>
- </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.