dongyanzhui0524 2014-06-15 14:36
浏览 52
已采纳

无法通过XML文件解析器读取任意文件

So I've wanted to create a very basic XML file parser that imports XML styles.

<?php
//error_reporting(0);

$XSLT = new XSLTProcessor();
$XML = new DOMDocument();
$XSL = new DOMDocument();

$XSL->load($_GET['file']);
$XSLT->importStyleSheet($XSL);

print $XSLT->transformToXML($XML);

Now I need to read an arbitrary file like this:

http://localhost/parser.php?file=style.xml

Given that I find it hard to troubleshoot as to why I cannot seem to read a .txt file on the local filesystem in the same directory.

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:template match='/'>
        <xsl:copy-of select="document('message.txt')"/>
    </xsl:template>
</xsl:stylesheet>
  • 写回答

1条回答 默认 最新

  • dragonfly9527 2014-06-15 14:40
    关注

    The document() function requires well-formed XML. You can't use it to read a plain text document. Try using it to read an XML document in the same directory. It should work:

    <xsl:copy-of select="document('message.xml')"/> <!-- message.xml is well formed XML -->
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题