PHP XML Reading
How can i retrieve categoryname from given xml file using php
<cate开发者_C百科gories>
<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
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 & Jeans" categorylevel="2"/>
</categories>'
);
foreach ($categories->category as $category)
{
echo $category['categoryname'], "<br />\n";
}
精彩评论