PHP5对象simplexml的详细分析_PHP教程

php中文网
发布: 2016-07-15 13:29:56
原创
1100人浏览过

北极象沉浸式AI翻译
北极象沉浸式AI翻译

免费的北极象沉浸式AI翻译 - 带您走进沉浸式AI的双语对照体验

北极象沉浸式AI翻译 0
查看详情 北极象沉浸式AI翻译

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示例,再加上自己的了解,应该能够充分的认识这一新增的函数。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446334.htmlTechArticlesimplexml_load_file(str file); 将一个xml文档载入一个simplexml对象中,此方法返回一个句柄 simplexml_load_string(str string);将一段xml文档载入一个simple...
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号