嗨,我想找到一个带有文本字符串“CAT1”的 xml 节点并显示,但我似乎无法正确处理。有人可以告诉我出了什么问题。
---目录.xml---
<?xml version="1.0" encoding="ISO-8859-1"?>
<Catalog>
<Category>
<Name>CAT1</Name>
<Location>
<Room> Alpha </Room>
</Location>
</Category>
<Category>
<Name>CAT2</Name>
<Location>
<Room> Bravo </Room>
</Location>
</Category>
<Category>
<Name>CAT3</Name>
<Location>
<Room> Charlie </Room>
</Location>
</Category>
<Category>
<Name>CAT4</Name>
<Location>
<Room> Delta </Room>
</Location>
</Category>
</Catalog>
---arr0.php---
<?php
$catalog = simplexml_load_file("catalog.xml");
$category = $catalog->Category;
$name = $category->Name;
$location = $category->Location;
$room = $location->Room;
for ($i = 0; $i <= 22; $i++)
{
$display = $catalog->xpath("//Category/Name[contains(text("CAT1"),'".$category[$i]->$name."']/parent::");
{
echo $display;
echo $room;
}
}
?>
结果是显示节点 [Category][Name] = CAT1, [Location][Room] 下列出的所有详细信息,但显示错误
解析错误:语法错误,第 11 行 /home/a3440614/public_html/arr0.php 中的意外 T_STRING
任何纠正和简化它的帮助表示赞赏。
谢谢