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;
}
精彩评论