我正在使用 SimpleXML 循环遍历 XML 文件,并尝试每次从 Previous 和 Next 节点中提取特定的数据(特别是series->displayname属性)。
以下是 XML 结构的示例:
<comic>
<id>117</id>
<index>1</index>
<mainsection>
<pagecount>33</pagecount>
<series>
<displayname>Amazing Story</displayname>
<sortname>Amazing Story</sortname>
</series>
</mainsection>
</comic>
<comic>
<id>102</id>
<index>1</index>
<mainsection>
<pagecount>33</pagecount>
<series>
<displayname>Fantastic Tale</displayname>
<sortname>Fantastic Tale</sortname>
</series>
</mainsection>
</comic>
<comic>
<id>85</id>
<index>1</index>
<mainsection>
<pagecount>33</pagecount>
<series>
<displayname>The Great Tale</displayname>
<sortname>The Great Tale</sortname>
</series>
</mainsection>
</comic>
这是我在循环中使用的结构示例:
$prevIssue = $comic->xpath('preceding-sibling::*')->mainsection->series->displayname;
$nextIssue = $comic->xpath('following-sibling::*')->mainsection->series->displayname;
echo '
<li class="issue" id="' . $seriesCat . '">
<h3>' . $comicSeriresName . '</h3>
<div id="details">
<span id="publisher">' . $comicPublisher . '</span><br>
The last series was called "' . $prevIssue . '<br>
The next series is called "' . $nextIssue . '<br>
</div>
</li>';
但是,“nextIssue”和“prevIssue”变量不起作用。他们返回一个空白结果。我究竟做错了什么?
非常感谢任何指导。