私は誰かが私を助けてくれるかどうか疑問に思います。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 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>
このページのデータは、ファイル「files.xml」から得られます。このファイルの抽出は以下のとおりです。私がやりたいこと
は<?xml version="1.0" encoding="utf-8" ?>
- <files>
<file name="Test 1/article-0-07D01B74000005DC-138_468x617.jpg" source="article-0-07D01B74000005DC-138_468x617.jpg" size="143110" originalname="article-0-07D01B74000005DC-138_468x617.jpg" thumbnail="article-0-07D01B74000005DC-138_468x617.jpg" description="No description provided" userid="1" locationid="1" folder="Test_1" />
</files>
これらが「1」の値を持っていた「locationid」「ユーザID」とによると、テストの目的のために、より具体的には、レコードが返さフィルタです。
私はXML 'Select Where' Statementで、このサイトからいくつかの有用な指導を受けたい、とそれに続く「XPathの」チュートリアルから私は私が私の最上部にある使用するための正しいXPathのコードだろうと思ったものをまとめて読みました'ギャラリー'ページのスクリプト。
しかし、私は次のエラーを受け取るこれを実行しようとしたとき:
Parse error: syntax error, unexpected '=' in /homepages/2/d333603417/htdocs/development/gallery.php on line 16
それは問題が「等しい」であることは明らかだが、私は戻って行ってきたとき、チュートリアルでは、これは正しい構文のように見えます。
私はちょうど誰かがこれを見て、私が間違っている場所を教えてくれたかどうか疑問に思った。
感謝
改正の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
$galleryPath = 'UploadedFiles/';
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
/files/file[@userid="1" and @locationid="1"];
?>
こんにちは、これには多くの感謝を。私はすでに私が持っているスクリプトに加えて何を含める必要があるのか分からないので、ここで私の深みからかなり外に出ていることを認めなければなりません。私が元々含んでいたコードは、私が作業していたチュートリアルから来ました。私は '$ path =" files [userid = 1]/originalname/folder/description/source/thumbnail ";'残念ながらそれはまだすべてのレコードを取得します。種類: – IRHM
"files [userid = 1]/originalname/folder/description/source/thumbnail"というクエリをどのようにして作成したかわかりません。 –
XMLから、 "originalname"、 "folder"、 "description"などのような "file"の属性があります。この場合、クエリは "/ files/file [@ userid =" 1 " ] "を入力してください。より多くの属性で検索する場合は、"/files/file [@ userid = "1"と@ originalname = "somename"] "など。 –