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
- 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-13 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.
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...