tags:

views:

39

answers:

2

How can i retrieve categoryname from given xml file using php

<categories>
<category categoryid="1100" categoryname="Baby Clothing" categorylevel="1">
<category categoryid="1101" categoryname="Dresses" categorylevel="2">
</category>
<category categoryid="1102" categoryname="Trousers & Jeans" categorylevel="2">      
</category>
<categories>

please help me

A: 

There is a simple tutorial here. You will need to show us the xml file and your code so that we can help you more.

Shoban
Ajith
A: 

The XML you have posted is very invalid (the & character must be escaped and tags must be closed), but here's how to exploit some similar XML using SimpleXML.

$categories = simplexml_load_string(
    '<categories>
        <category categoryid="1100" categoryname="Baby Clothing" categorylevel="1"/>
        <category categoryid="1101" categoryname="Dresses" categorylevel="2"/>
        <category categoryid="1102" categoryname="Trousers &amp; Jeans" categorylevel="2"/>
    </categories>'
);

foreach ($categories->category as $category)
{
    echo $category['categoryname'], "<br />\n";
}
Josh Davis
hi Josh Davis you are great.Thanks...very very thanks
Ajith