xml文件内容大致如下
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type='text/xsl' href='XSLTFile.xsl'?>
<root>
<node>Hello..</node>
</root>
我在default.aspx.cs里面如下操作
protected void Page_Load(object sender, EventArgs e)
    {
        Response.WriteFile(Server.MapPath("XMLFile.xml"));
    }
出现下来错误
XML 文档只能有一个顶层元素。处理资源 
'http://localhost:1130/Xml/Default.aspx' 时出错。第 318 行,位置: 2 <html xmlns="http://www.w3.org/1999/xhtml" >
-^

解决方案 »

  1.   

    WriteFile是将指定的文件直接写入HTTP内容输出流 
      

  2.   

    重载Page.Render,
    protected override void Render(HtmlTextWriter output) {
        //用output写
    }
      

  3.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    }
    protected override void Render(HtmlTextWriter output) 
    {
    string str=
    @"<?xml version=""1.0"" encoding=""utf-8"" ?>
    <?xml-stylesheet type='text/xsl' href='XSLTFile.xsl'?>
    <root>
    <node>Hello..</node>
    </root>";
    output.Write(str);
    }
      

  4.   

    先把文件内容读到字符串,然后html encode,输出。
      

  5.   

    谢谢、刚才查了MSDN也解决了、、、
    给分:)