发送XML内容前,先发送header.header("Content-type: text/xml");

解决方案 »

  1.   

    示例:
    ========================================
    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>
      

  2.   

    html和xml一样,只是一种语言规范。
    同样,在输出内容前,要加上 header("Content-Type: text/xml");
      

  3.   

    感谢大家 特别是netvt(唯她) 的帮助 
     但是 我试了 还是出现我说的第2种情况 (要刷新才能看得见)
     不知道服务器端要不要做什么配置呢?
      

  4.   

    在服务器中,应定义有XML的MIME类型,
    一般的WEB服务器中默认已定义.如果已定义.
    先看看你的代码?
      

  5.   

    测试一下你的浏览器,看行不行?
    地址:
    http://xingtai.51.net/netvt/menu.php我这里测试没问题 IE 6.0.2800.1106 SP1
      

  6.   

    上面得地址在我的IE能正常显示
        现在我意识到另外一个问题
       好象这样做没有什么意义
    不知道我用数据库储藏数据
       又想赶赶潮流 想试一下XML  有什么好的解决方案吗?
      

  7.   

    上面这个网址在Mozilla,Netscape,MozillaFirebird中不能显示
      

  8.   

    因为未采用W3C标准来写xsl文件.
    Mozilla对ms标准的xsl支持不太好!