1

我使用XML SQL 查询从表中检索前 10 个值,然后通过 asp.net 页面显示这些值,以将结果页面的 URL 传递给 flash Game 以打印前 10 个值。我的代码做得很好,我在 aspx 页面上很好地检索了XML查询。但是我单击页面查看源页面,它检索了HTML 页面中的xml值,但 Flash 游戏不会复制这些值。那么如何在 xml 页面中显示 xml 文件呢?.

询问

SELECT DISTINCT TOP (10)
    fbid ,   
    Name as fbname,
    Score  as fbscore ,
    Img  as fbimg      
FROM 
    dbo.FB_Player
ORDER BY 
    Score DESC 
FOR XML PATH('Player'), ROOT('AllPlayers')

C# 代码

using (System.Data.SqlClient.SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["fbgame"].ConnectionString))
    using (System.Data.SqlClient.SqlCommand cmd = c.CreateCommand())
    {
        cmd.CommandText = "procGetPlayerScore";
        cmd.CommandType = CommandType.StoredProcedure;

        c.Open();

        System.Xml.XmlReader r = cmd.ExecuteXmlReader();
        string playersXml = cmd.ExecuteScalar().ToString();
        string theXML = Server.HtmlEncode(File.ReadAllText(Server.MapPath("Top10.xml")));
        lit1.Text= playersXml;
        System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(Response.Output);

        c.Close();
    }

使用新代码后出错

在此处输入图像描述

4

1 回答 1

1

代码看起来不正常,它似乎并没有真正执行写入。就在我的脑海中,我会试试这个:

C#

using (System.Data.SqlClient.SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["fbgame"].ConnectionString))
    using (System.Data.SqlClient.SqlCommand cmd = c.CreateCommand())
    {
        cmd.CommandText = "procGetPlayerScore";
        cmd.CommandType = CommandType.StoredProcedure;

        c.Open();

        System.Xml.XmlReader r = cmd.ExecuteXmlReader();
        XmlDocument document = new XmlDocument();
        document.Load(r);

        Response.ContentType = "text/xml";
        document.Save(Response.Output);

        c.Close();
    }
}
于 2013-09-07T00:58:12.397 回答