⊗ppSpXmTGN 27 of 83 menu

Group of XML Tags with Nesting in PHP

Now suppose we have several tags containing nested ones inside:

<root> <tag> <elem>text1</elem> </tag> <tag> <elem>text2</elem> </tag> <tag> <elem>text3</elem> </tag> </root>

Let's loop through our tags and output the values of the nested tags:

<?php foreach ($xml->tag as $tag) { echo $tag->elem; // 'text1', 'text2', 'text3' } ?>

Given the following XML:

<root> <user> <name>john</name> <surn>smit</surn> </user> <user> <name>eric</name> <surn>wils</surn> </user> <user> <name>kyle</name> <surn>tayl</surn> </user> </root>

Display the name and surname of each user.

Given the following XML:

<root> <product cost="100" amount="3"> <name>prod1</name> <category>cat1</category> </product> <product cost="200" amount="4"> <name>prod2</name> <category>cat2</category> </product> <product cost="300" amount="5"> <name>prod3</name> <category>cat3</category> </product> </root>

Display the name, category, price and quantity of each product.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline