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 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组