我有一个小问题。我需要解析一个文件并用结果填充Web横幅。问题是,文件名为:“_banner_products.php”,它的内容如下:解析带.php扩展名和php头的xml文件
<?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");
除此之外,遍历你应该使用类似http://www.php.net/manual/en/simplexml.examples-的例子#4码的XML basic.php – Bendihossan 2012-04-17 13:17:24
如果我把完整路径 'http:// localhost/MySite/_banner_products.php' 它给我 'I/O警告:未能加载外部实体“/_banner_products.php”' – JoonasL 2012-04-17 13:26:20
它应该工作,如果你把它@JoonasL – Baba 2012-04-17 13:27:24