开发者

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 &amp; Jeans" categorylevel="2"/>
    </categories>'
);

foreach ($categories->category as $category)
{
    echo $category['categoryname'], "<br />\n";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜