请大家帮帮忙:能不能用PHP象生成HTML一样动态生成XML发布信息?(急。。。。 急) 发送XML内容前,先发送header.header("Content-type: text/xml"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 示例:========================================menu.php文件:<?php header("Content-Type: text/xml");echo "<?xml version='1.0' encoding='gb2312' ?>\n";echo "<?xml-stylesheet type='text/xsl' href='menu_xsl.php' ?>\n";?><root href="preview.php" image="" value="ONE"> <topmenu href="allset.php" image="" value="ONE_ONE"> <menu href="status.php" image="">ONE_ONE_ONE</menu> <menu href="file_man.php" image="">ONE_ONE_TWO</menu> <menu href="select_tpl.php" image="">ONE_ONE_THREE</menu> </topmenu> <topmenu href="" image="" value="后台" /> <topmenu href="exit.php" image="" value="EXIT" /></root>------------------------------------------menu_xsl.php文件:<?php header("Content-Type: text/xml");echo "<?xml version='1.0' encoding='gb2312' ?>\n";?><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"><xsl:template match="/"> <html> <STYLE TYPE="text/css" TITLE=""> TABLE{ background-color:#fffaf0; border-width : 1px 1px 1px 1px; } TD{ color:#0000ff; height:18; font-size:12px; } A{ color: #000033; text-decoration: none; } A:VISITED{ color: #000055; text-decoration: none; } A:HOVER{ text-decoration: underline; color:#ff0000; } A:ACTIVE{ color: #0000ff; text-decoration: underline; } </STYLE> <body> <table border="0" cellspacing="1" cellpadding="0" width="300"> <tr> <td ></td> <td >名称</td> <td >链接</td> </tr> <tr><td colspan="3"><font color="red">网站名称</font> <xsl:for-each select="root"> <xsl:value-of select="@value"/> </xsl:for-each> </td> </tr> <xsl:for-each select="root/topmenu"> <tr> <td colspan="3"> <xsl:value-of select="@value" /> </td> </tr> <xsl:for-each select="menu"> <tr> <td width="23"></td> <td> <xsl:element name="a"> <xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute> <xsl:value-of select="." /> </xsl:element> </td> <td style="color:red;font-style:italic;"> <xsl:value-of select="@href" /> </td> </tr> </xsl:for-each> </xsl:for-each> <tr><td colspan='2' ><hr /></td> <td> <script language="JavaScript"> <xsl:comment> tmpDate = new Date(); date = tmpDate.getDate(); month= tmpDate.getMonth() + 1 ; year= tmpDate.getYear(); document.write(year); document.write("."); document.write(month); document.write("."); document.write(date); </xsl:comment> </script> </td> </tr> </table> </body> </html></xsl:template></xsl:stylesheet> html和xml一样,只是一种语言规范。同样,在输出内容前,要加上 header("Content-Type: text/xml"); 感谢大家 特别是netvt(唯她) 的帮助 但是 我试了 还是出现我说的第2种情况 (要刷新才能看得见) 不知道服务器端要不要做什么配置呢? 在服务器中,应定义有XML的MIME类型,一般的WEB服务器中默认已定义.如果已定义.先看看你的代码? 测试一下你的浏览器,看行不行?地址:http://xingtai.51.net/netvt/menu.php我这里测试没问题 IE 6.0.2800.1106 SP1 上面得地址在我的IE能正常显示 现在我意识到另外一个问题 好象这样做没有什么意义不知道我用数据库储藏数据 又想赶赶潮流 想试一下XML 有什么好的解决方案吗? 上面这个网址在Mozilla,Netscape,MozillaFirebird中不能显示 因为未采用W3C标准来写xsl文件.Mozilla对ms标准的xsl支持不太好! mysql查询的1个存储过程,显示2个查询结果,怎么在PHP里把2个结果显示出来 关于php __autoload函数的疑问 php函数调用问题 windows 下NGINX 做反向代理服务器 不同目录下的HTML缓存时间不同设置 where子查询懵了, php发邮件遇到的问题? 为什么在RedHatLinux8.0下PHP不支持MySQL? 关于session的一个问题 请教MYPHP 的CHAR字段 字符串显示的问题!!!! 谁知道如何用PHP操作XML? 晕~!死,看你们怎么办 ,在线等~!
========================================
menu.php文件:
<?php
header("Content-Type: text/xml");
echo "<?xml version='1.0' encoding='gb2312' ?>\n";
echo "<?xml-stylesheet type='text/xsl' href='menu_xsl.php' ?>\n";
?>
<root href="preview.php" image="" value="ONE">
<topmenu href="allset.php" image="" value="ONE_ONE">
<menu href="status.php" image="">ONE_ONE_ONE</menu>
<menu href="file_man.php" image="">ONE_ONE_TWO</menu>
<menu href="select_tpl.php" image="">ONE_ONE_THREE</menu>
</topmenu> <topmenu href="" image="" value="后台" /> <topmenu href="exit.php" image="" value="EXIT" />
</root>------------------------------------------
menu_xsl.php文件:
<?php
header("Content-Type: text/xml");
echo "<?xml version='1.0' encoding='gb2312' ?>\n";
?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<STYLE TYPE="text/css" TITLE="">
TABLE{
background-color:#fffaf0;
border-width : 1px 1px 1px 1px;
}
TD{
color:#0000ff;
height:18;
font-size:12px;
}
A{
color: #000033;
text-decoration: none;
}
A:VISITED{
color: #000055;
text-decoration: none;
}
A:HOVER{
text-decoration: underline;
color:#ff0000;
}
A:ACTIVE{
color: #0000ff;
text-decoration: underline;
} </STYLE>
<body>
<table border="0" cellspacing="1" cellpadding="0" width="300">
<tr>
<td ></td>
<td >名称</td>
<td >链接</td>
</tr>
<tr><td colspan="3"><font color="red">网站名称</font>
<xsl:for-each select="root">
<xsl:value-of select="@value"/>
</xsl:for-each>
</td>
</tr>
<xsl:for-each select="root/topmenu">
<tr>
<td colspan="3">
<xsl:value-of select="@value" />
</td>
</tr>
<xsl:for-each select="menu">
<tr>
<td width="23"></td>
<td>
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
</td>
<td style="color:red;font-style:italic;">
<xsl:value-of select="@href" />
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
<tr><td colspan='2' ><hr /></td>
<td>
<script language="JavaScript">
<xsl:comment>
tmpDate = new Date();
date = tmpDate.getDate();
month= tmpDate.getMonth() + 1 ;
year= tmpDate.getYear();
document.write(year);
document.write(".");
document.write(month);
document.write(".");
document.write(date);
</xsl:comment>
</script>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
同样,在输出内容前,要加上 header("Content-Type: text/xml");
但是 我试了 还是出现我说的第2种情况 (要刷新才能看得见)
不知道服务器端要不要做什么配置呢?
一般的WEB服务器中默认已定义.如果已定义.
先看看你的代码?
地址:
http://xingtai.51.net/netvt/menu.php我这里测试没问题 IE 6.0.2800.1106 SP1
现在我意识到另外一个问题
好象这样做没有什么意义
不知道我用数据库储藏数据
又想赶赶潮流 想试一下XML 有什么好的解决方案吗?
Mozilla对ms标准的xsl支持不太好!