打印所有节点 SimpleXML
这是我的第一个 xml 解析器脚本。 我的代码:
<?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>
</note>
</book>
";
$xml = new SimpleXMLElement($xmlstring);
foreach($xml->note as $note){
echo $note["to"] . $note["from"] . $note["heading"] . $note["body"];
}
?>
我想打印 note
孩子们。但这段代码不打印任何内容.. 问题出在哪里?
谢谢...
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>
</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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
note
是一个 SimpleXMLObject。因此,您需要指针(箭头)表示法而不是数组(括号)表示法。note
is a SimpleXMLObject. So you would need to pointer (arrow) notation not array (bracket) notation.