Home php教程 php手册 使用PHP 5.0 轻松解析XML文档(4)

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

Jun 21, 2016 am 09:15 AM
array name price

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                )        ))
Copy after login

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

<?xml version="1.0" encoding="GB2312" ?><br><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>
Copy after login



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera line Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera line Sep 07, 2024 am 09:34 AM

Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

FiiO CP13 cassette player launches with transparent retro look FiiO CP13 cassette player launches with transparent retro look Jun 16, 2024 am 09:52 AM

TheFiiOCP13cassetteplayerwasannouncedinJanuary.Now,FiiOisexpandingitsportfoliowithtwonewmodels-onewitharedfrontandonewithatransparentfront.Thelatternotonlyperfectlymatchestheretrocharmoftheangulardesign,butalso

Klipsch unveils Flexus Core 300 flagship soundbar with 8K support, 12 speakers and room correction Klipsch unveils Flexus Core 300 flagship soundbar with 8K support, 12 speakers and room correction Sep 05, 2024 am 10:16 AM

The Klipsch Flexus Core 300 is the top model in the series and is positioned above the already available Flexus Core 200 in the company's soundbar line-up. According to Klipsch, this is the first soundbar in the world whose sound can be adapted to th

Light Phone 3 launches with 50% discount, monochrome OLED and minimalist design Light Phone 3 launches with 50% discount, monochrome OLED and minimalist design Jun 13, 2024 pm 10:18 PM

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Jun 19, 2024 am 09:55 AM

Shortly after Tesla launched the Model 3 Highland refresh towards the end of last year, the US federal EV tax incentive rules changed, cutting the potential discount in half for eligible buyers because of Tesla's use of Chinese LFP cells in the new M

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Simple and clear method to use PHP array_merge_recursive() function Simple and clear method to use PHP array_merge_recursive() function Jun 27, 2023 pm 01:48 PM

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values ​​of the same keys, making the program design more flexible. array_merge

See all articles