我的查询选择 xml 中的字段。我需要的是不在一行中显示xml
<AllPlayers><Player><fbid>1236598</fbid><fbname>joan</fbname><fbscore>99999999</fbscore></Player><Player><fbid>55559999888</fbid><fbname>smith</fbname><fbscore>99999999</fbscore></Player></AllPlayers>
但作为:
<AllPlayers>
<Player>
<fbid>1236598</fbid>
<fbname>Mohamed Hamam</fbname>
<fbscore>99999999</fbscore>
</Player>
<Player>
<fbid>55559999888</fbid>
<fbname>mostafaa Hamam</fbname>
<fbscore>99999999</fbscore>
</Player>
</AllPlayers>
我的查询:
ALTER PROCEDURE [dbo].[procGetPlayerScore]
AS BEGIN
SELECT DISTINCT TOP (10)
fbid ,
Name as fbname,
Score as fbscore
FROM
dbo.FB_Player
ORDER BY
Score DESC
FOR XML PATH('Player'), ROOT('AllPlayers')
END
asp页面:
Response.Expires = -1;
Response.ContentType = "text/xml";
using(System.Data.SqlClient.SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["x"].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();
xmlc.InnerText = playersXml;
System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(Response.Output);
c.Close();
}