Xml 使用Xpath检索所选记录
不知是否有人能帮助我 我正在使用下面的脚本创建一个“图库”页面Xml 使用Xpath检索所选记录,xml,xpath,Xml,Xpath,不知是否有人能帮助我 我正在使用下面的脚本创建一个“图库”页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php //This variable specifies
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
$galleryPath = 'UploadedFiles/';
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
path="files[userid=1]/originalname/folder/description/source/thumbnail";
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].childNodes[0].nodeValue);
}
}
?>
<head>
<title>Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" />
<link href="Styles/style.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="Styles/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { $('a.fancybox').fancybox(); });
</script>
<style type="text/css">
<!--
.style1 {
font-size: 14px;
margin-right: 110px;
}
.style4 {font-size: 12px}
-->
</style>
</head>
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;">
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> ← View All Uploaded Images </div>
<form id="gallery" class="page">
<div id="container">
<div id="center">
<div class="aB">
<div class="aB-B">
<?php if ('Uploaded files' != $current['title']) :?>
<?php endif;?>
<label>
<input name="userid" type="text" id="userid" value="1" />
<input name="locationid" type="text" id="locationid" value="1" />
</label>
<div class="demo">
<div class="inner">
<div class="container">
<div class="gallery">
<ul class="gallery-image-list">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
$thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));
?>
<li class="item">
<a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview"
alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a> </li>
<li class="item"></li>
<p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
<b>Image contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br />
<?php endfor; ?>
</li>
</p>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="aB-a"> </div>
</div>
</div>
</div>
</form>
</body>
</html>
第16行是
path="files[userid=1]/originalname/folder/description/source/thumbnail";
如果这是PHP代码,您需要在路径
之前使用$
该行下面的代码似乎是Javascript。因此,您可能应该使用如下语法将PHP变量$path传递到Javascript中:
var path = "<?=$path ?>";
var path=”“;
嗯,
- 伊莱
$path=“files[userid=1]/originalname/folder/description/source/thumbnail”但是不幸的是,它仍然检索所有记录。Kind Regard我不清楚您是如何查询“files[userid=1]/originalname/folder/description/source/thumbnail”的。从XML来看,“originalname”、“folder”、“description”等都是“file”的属性,在这种情况下,对于userid 1,查询可能类似于“/files/file[@userid=“1”]”。如果您想按更多属性进行搜索,请选择“/files/file[@userid=“1”和@originalname=“somename”]”等。您好,非常感谢您抽出时间回复并帮助我。我从阅读教程中获得了原始xpath,这显然我不理解。我在我的脚本中使用了您建议的代码,并将其添加到我的原始帖子中,以向您展示它现在的样子,但不幸的是,我收到了以下错误:解析错误:语法错误,在/homepages/2/d33603417/htdocs/development/gallery.php的第16行
,第16行是xpath行。你能告诉我哪里出了问题吗。问候
path="files[userid=1]/originalname/folder/description/source/thumbnail";
var path = "<?=$path ?>";