• 技术文章 >php教程 >php手册

    使用PHP 5.0 轻松解析XML文档(4)

    2016-06-21 09:15:23原创380

    xml

    下面是例子运行对结果:

      下面是通过函数getSaveData()返回的整个xml数据的数组

    Array(    [name] => 华联    [address] => 北京长安街-9999号    [desc] => 连锁超市    [cat_food] => Array        (            [attrs] => Array                (                    [id] => food                )            [goods_food11] => Array                (                    [name] => food11                    [price] => 12.90                    [attrs] => Array                        (                            [id] => food11                        )                )            [goods_food12] => Array                (                    [name] => food12                    [price] => 22.10                    [desc] => Array                        (                            [value] => 好东西推荐                            [attrs] => Array                                (                                    [creator] => hahawen                                )                        )                    [attrs] => Array                        (                            [id] => food12                        )                )        )    [cat_1] => Array        (            [goods_tel21] => Array                (                    [name] => tel21                    [price] => 1290                    [attrs] => Array                        (                            [id] => tel21                        )                )        )    [cat_coat] => Array        (            [attrs] => Array                (                    [id] => coat                )            [goods_coat31] => Array                (                    [name] => coat31                    [price] => 112                    [attrs] => Array                        (                            [id] => coat31                        )                )            [goods_coat32] => Array                (                    [name] => coat32                    [price] => 45                    [attrs] => Array                        (                            [id] => coat32                        )                )        )    [special_hot] => Array        (            [attrs] => Array                (                    [id] => hot                )            [goods_0] => Array                (                    [name] => hot41                    [price] => 99                )        ))

      下面是通过setValue()函数,给给根节点添加信息,添加后显示出结果xml文件的内容

    <?xml version="1.0" encoding="GB2312" ?>
    <shop> <name>华联</name> <address>北京长安街-9999号</address> <desc>连锁超市</desc> <telphone>123456789</telphone> <cat id="food"> <goods id="food11"> <name>food11</name> <price>12.90</price> </goods> <goods id="food12"> <name>food12</name> <price>22.10</price> <desc creator="hahawen">好东西推荐</desc> </goods> </cat> <cat> <goods id="tel21"> <name>tel21</name> <price>1290</price> </goods> </cat> <cat id="coat"> <goods id="coat31"> <name>coat31</name> <price>112</price> </goods> <goods id="coat32"> <name>coat32</name> <price>45</price> </goods> </cat> <special id="hot"> <goods> <name>hot41</name> <price>99</price> </goods> </special></shop>



    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:Array name price goods attrs
    上一篇:实例学习PHP之FastTemplate 模板篇 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • Codeigniter框架实现获取分页数据和总条数的方法• php批量添加数据与批量更新数据的实现方法,php添加数据• PHP弹出提示框并跳转到新页面(重定向)• php中header()实现页面跳方法• PHP之判断用户语言跳转网页
    1/1

    PHP中文网