【发布时间】:2012-04-17 13:07:06
【问题描述】:
我有一个小问题。我需要解析一个文件并用结果填充一个网页横幅。问题是,该文件名为:“_banner_products.php”,其内容如下:
<?php header('Content-Type:text/xml'); ?><?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<carouselle>
<firstLayer>
<layerName>Leica Disto X310</layerName>
<layerProduct>Disto X310</layerProduct>
<layerPic>http://www.leicaestonia.ee/extensions/boxes_design/flashpics/1334482548.jpg</layerPic>
<layerPrice>0,-</layerPrice>
<layerPriceOld></layerPriceOld>
<layerLink>http://www.leicaestonia.ee/index.php?id=11627</layerLink>
<layerTimer>01.05.2012 00:00</layerTimer>
</firstLayer>
<firstLayer>
.....
.....
</firstLayer>
</carouselle>
如何循环遍历这个文件以将所有“firstLayer”子级分组为一个,依此类推.. 如果我只是使用:
$file = fopen("_banner_products.php", "r");
while (!feof($file)){
$line = fgets($file);
}
simplexml_load_file 抛出这个- "_banner_products.php:1: 解析器错误:需要开始标签,'
然后我只得到 <...> 标记的内容,这意味着我无法区分我是否已经超出范围。
感谢任何人的回复。如果有什么不清楚的地方,我会试着解释更多。
编辑。 感谢您的解决方案,确实使用完整的 URL 有效:
simplexml_load_file("http://localhost/MySite/_banner_products.php");
【问题讨论】:
标签: php xml-parsing