开发者

print all nodes SimpleXML

It's my first xml parser script. My code:

<?php
$xmlstring = "
<book>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    <note>
    <to>Tove1</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </开发者_JS百科note>
</book>
";

$xml = new SimpleXMLElement($xmlstring);
foreach($xml->note as $note){
    echo $note["to"] . $note["from"] . $note["heading"] . $note["body"];
}
?>

i want to print note children. but this code doesn't print anything .. Where is the problem?

Thanks...


note is a SimpleXMLObject. So you would need to pointer (arrow) notation not array (bracket) notation.

foreach($xml->note as $note){
    echo $note->to . $note->from . $note->heading . $note->body;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜