simplexml_load_file(str file); 将一个xml文档载入一个simplexml对象中,此方法返回一个句柄
simplexml_load_string(str string);将一段xml文档载入一个simplexml对象中,此方法返回一个句柄
simplexml_import_dom(data) 该函数把一个dom节点转为simplexml对象,其中data为实用的DOM节点
$simplexml->addAttribute(name,value) 给simplexml对象元素添加一个属性,注意,是simplexml对象元素,不是simplexml对象句柄。
$simplexml->addChlid(name,value)给指定的XML节点添加一个子节点
立即学习“PHP免费学习笔记(深入)”;
$simplexml->asXML() 从SimpleXMLElement对象中以一个字符串的形式返回XML文档,可以当作保存xml文档来来用
$simplexml->attributes() 返回由PHP5对象simplexml元素节点的属性组成的数组,
运行上面代码会打印出以个数组,Array ( [@attributes] => Array ( [name] => cx,html [tt] => ddd ) )
可见,$simplexml->attributes()得到的是一个xml元素节点的所有属性,不过被包含在一个[@attributes]数组中,所以要通过$xml = $xml['@attributes']来获得
$simplexml->Children() 返回simplexml对象元素节点的孩子组成的数组
$simplexml->__construct() 创建一个新的XML文档
$simplexml->getDocNamespaces() 该函数返回$simplexml对象定义的命名空间
$simplexml->getName() 返回$simplexml对象元素的名称,即标签名
$simplexml->getNamespaces() 返回$simplexml对象使用的命名空间
$simplexml->registerXpathNamespace() 该函数为下一次XPATH查询创建命名空间语境
$simplexml->xpath() 使用xpath的语法来解析一个PHP5对象simplexml
实例代码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>?></FONT></STRONG></SPAN><SPAN> </SPAN></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><LI class=alt><SPAN> </SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN><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></SPAN></LI></OL>
我们可以结合上面的PHP5对象simplexml示例,再加上自己的了解,应该能够充分的认识这一新增的函数。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号