嘿,伙计们,我在数据库中存储了一些xml文件,想把它们用于xslt转换。但我无法加载它进行转换,它们被下载到PC上。我想处理它,而不是下载。
这是我的代码:我正在访问带有id的文件。
// Fetch the file information
$query = "
SELECT `pname`,`pdata`
FROM `plist`
WHERE `pid` = {$id}";
$result = $dbLink->query($query);
if ($result) {
// Make sure the result is valid
if ($result->num_rows == 1) {
// Get the row
$row = mysqli_fetch_row($result);
echo "$row[0]";
header("Content-Type:text/xml");
header("Content-Disposition: inline");
echo $row['pdata'];
}
mysqli_free_result($result);
---这里缺少获取文件数据的东西--
直到现在它被下载,但我想继续转换
$xml = new DOMDocument;
$xml->load(what goes here??);
$xsl = new DOMDocument;
$xsl->load('file.xslt');
//etc
感谢任何帮助。
如果您有一个包含XML的字符串,那么我认为您可以使用$xml->loadXML($row['pdata'])
来解析XML。
我后来发现的工作解决方案…:)
<?php
if (isset($_GET['id'])) {
// Get the id
$id = intval($_GET['id']);
// Make sure the name is in fact a valid
if ($id <= 0) {
die('The id is invalid!');
} else {
// Connect to the database
include 'config.php';
}
// Fetch the file information
$query = "select id, name, data from data_table where id ={$id};";
$resultx = $mysqli->query($query) or die($mysqli->error . __LINE__);
$arr = array();
if ($resultx->num_rows > 0) {
while ($row = $resultx->fetch_assoc()) {
$arr[] = $row['tdata'];
}
}
$string = implode(",", $arr);
// Load XML file
$xml = new DOMDocument; // create new document
$xml->loadXML($string); // load string to it