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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器