在下面的代码中,它将打印xml文件或字符串的所有项目。但如果,我想不打印特定项目怎么办?假设,我不想打印第一个项目,那我该怎么办?
<?php
$note = <<<XML
<?xml version='1.0' ?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br>";
}
答案 0 :(得分:0)
使用continue
语句跳过一些标记:
$skipTag = 'from';
foreach($xml->children() as $child) {
if ($child->getName() == $skipTag) continue;
echo $child->getName() . ": " . $child . "\n";
}