首页 > 开发 > PHP > 正文

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

2024-05-04 22:53:55
字体:
来源:转载
供稿:网友
下面是例子运行对结果:

  下面是通过函数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>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表