simplexml_load_file(str file); Load an xml document into a simplexml object. This method returns a handle.
simplexml_load_string(str string); Load an xml document into a simplexml object. Load 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, not a simplexml object handle.
$simplexml->addChlid(name,value) adds a child node to the specified XML node
$simplexml->asXML() as a string from the SimpleXMLElement object Returns an XML document, which can be used as a saved xml document
$simplexml->attributes() returns an array composed of attributes of the PHP5 object simplexml element node,
running the above code will Print out an array, Array ( [@attributes] => Array ( [name] => cx,html [tt] => ddd ) )
visible, $simplexml->attributes( ) gets all the attributes of an xml element node, but they are included in an [@attributes] array, so you need to get it through $xml = $xml['@attributes']
$simplexml-> ;Children() Returns an array composed of children of simplexml object element node
$simplexml->__construct() Creates a new XML document
$simplexml->getDocNamespaces() This function Returns the namespace defined by the $simplexml object
$simplexml->getName() returns the name of the element of the $simplexml object, that is, the tag name
$simplexml->getNamespaces() returns $simplexml The namespace used by the object
$simplexml->registerXpathNamespace() This function creates a namespace context for the next XPATH query
$simplexml->xpath() Use xpath syntax to Parse a PHP5 object simplexml
Example code 1
<ol class="dp-xml"> <li class="alt"> <span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>xml</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>version</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"1.0"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>encoding</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"gbk"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulXML</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span>Leapsoul-PHP网站开发</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span>http://www.leapsoul.cn</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span>分享PHP网站开发与建设的乐趣,教你如何建立网站</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span>David</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span>2009-05-13</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span>QQ:154130270</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"><span> </span></li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span>Leapsoul-PHP网站开发</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span>http://www.leapsoul.cn</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span>分享PHP网站开发与建设的乐趣,教你如何建立网站</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span>David</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span>2009-05-13</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span>QQ:154130270</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulXML</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> </ol>
We can combine the above PHP5 object simplexml example, plus With your own understanding, you should be able to fully understand this new function.