开发者

print all nodes SimpleXML

开发者 https://www.devze.com 2023-04-12 20:53 出处:网络
It\'s my first xml parser script. My code: <?php $xmlstring = \" <book> <note> <to>Tove</to>

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

精彩评论

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