在Firefox(和其他浏览器)中将PHP文件输出视为XML的方法如下:
<?php
header("Content-Type: text/xml");
这将设置HTTP响应头,指示浏览器将接收到的数据视为XML。
<?php
header("Content-Type: text/xml");
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<note>";
$xml .= "<to>Tove</to>";
$xml .= "<from>Jani</from>";
$xml .= "<heading>Reminder</heading>";
$xml .= "<body>Don't forget me this weekend!</body>";
$xml .= "</note>";
echo $xml;
?>
<?php
header("Content-Type: text/xml");
// 生成XML数据
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<note>";
$xml .= "<to>Tove</to>";
$xml .= "<from>Jani</from>";
$xml .= "<heading>Reminder</heading>";
$xml .= "<body>Don't forget me this weekend!</body>";
$xml .= "</note>";
// 生成XSLT样式表
$xslt = "<?xml version='1.0' encoding='UTF-8'?>";
$xslt .= "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>";
$xslt .= "<xsl:template match='/'>";
$xslt .= "<html>";
$xslt .= "<body>";
$xslt .=<table border='1'>";
$xslt .= "<tr>";
$xslt .= "<th>To</th>";
$xslt .= "<th>From</th>";
$xslt .= "<th>Heading</th>";
$xslt .= "<th>Body</th>";
$xslt .= "</tr>";
$xslt .= "<tr>";
$xslt .= "<td><xsl:value-of select='note/to'/></td>";
$xslt .= "<td><xsl:value-of select='note/from'/></td>";
$xslt .= "<td><xsl:value-of select='note/heading'/></td>";
$xslt .= "<td><xsl:value-of select='note/body'/></td>";
$xslt .= "</tr>";
$xslt .= "</table>";
$xslt .= "</body>";
$xslt .= "</html>";
$xslt .= "</xsl:template>";
$xslt .= "</xsl:stylesheet>";
// 合并XML和XSLT
$xml_doc = new DOMDocument();
$xml_doc->loadXML($xml);
$xslt_doc = new DOMDocument();
$xslt_doc->loadXML($xslt);
$proc = new XSLTProcessor();
$proc->importStyleSheet($xslt_doc);
echo $proc->transformToXML($xml_doc);
?>
这将在浏览器中以表格形式美观地显示XML数据。
推荐的腾讯云相关产品:腾讯云对象存储(COS)、腾讯云API网关、腾讯云云服务器、腾讯云数据库MySQL、腾讯云负载均衡、腾讯云CDN、腾讯云SSL证书、腾讯云监控告警、腾讯云自动化部署等。
腾讯云产品介绍链接地址:https://cloud.tencent.com/product