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