0
我是Xpath的新手,实际上只是今天第一次看到它,并且我在XPath中有一些问题,没有加载在XML中定义的图像。XML XPath问题
到目前为止,我有:
<page name = "home"><br />
<image>
<imagehome1>
<imge>resp.jpg</imge><br />
<class>right</class>
</imagehome1>
<imagehome2>
<imge></imge><br />
<class>right</class>
</imagehome2>
<imagehomebot>
<imge>cfr.png</imge><br />
<class>bottom</class>
</imagehomebot>
</image>
</page>
正如你可以看到我定义2个图像,1 imagehome1和imagehomebot 1,但是我的XPath代码只显示来自imagehomebot图像.....和我不知道为什么。
我的PHP的XPath代码:
<?
$nodes = $dom->xpath('/content/page/image/imagehome1');
if (count($nodes) > 0) {
if(!(string)$nodes[0]->imge){
$class = "";}
else{
$class3 = (string)$nodes[0]->class;
$img3 = (string)$nodes[0]->imge;}
}
?>
<div class="<? echo $class ?>">
<img src="imgs/<? echo $img1 ?>" />
</div>
<?
$nodes = $dom->xpath('/content/page/image/imagehome2');
if (count($nodes) > 0) {
if(!(string)$nodes[0]->imge){
$class = "";}
else{
$class3 = (string)$nodes[0]->class;
$img3 = (string)$nodes[0]->imge;}
}
?>
<div class="<? echo $class ?>">
<img src="imgs/<? echo $img2 ?>" />
</div>
</div>
<div id="box2">
<?
$nodes = $dom->xpath('/content/page/image/imagehomebot');
if (count($nodes) > 0) {
if(!(string)$nodes[0]->imge){
$class = "";}
else{
$class3 = (string)$nodes[0]->class;
$img3 = (string)$nodes[0]->imge;}
}
?>
<div class="<? echo $class3 ?>">
<img src="imgs/<? echo $img3 ?>" />
</div>
所有帮助深表感谢。 感谢
编辑:刚刚另一快看在我的代码,我想我知道为什么,该死的复制和粘贴哈哈......
是否存在所有这些图像? HTML输出是什么样的? – GolezTrol
实际显示imagehomebot图像的代码在哪里? – GolezTrol
它可能与“imgs”文件夹后面缺少的'/'有关,但由于它现在已经奇迹般地出现了,您的问题可能会得到解决,对吧? :) – GolezTrol