CREATE PROCEDURE [dbo].[GetStories]
@fromDate datetime,
@toDate datetime
AS
BEGIN
select dbo.Story.id,
description,
notes,
text,
publicationdate,
authorsnames,
keywords
from dbo.Story
inner join dbo.Status on dbo.Story.StatusId = dbo.Status.id
where publicationdate between @fromDate and @toDate
and dbo.Status.status = 'live'
order by publicationDate
FOR XML PATH('story'),
ROOT('stories')
END
其关键的步骤就是“FOR XML PATH(###), ROOT(###)”这部分。他告诉sqlserver返回的xml每一行都要有名为“story”的节点,并且xml文档的根节点名为“stories”
[WebMethod(Description = "Get stories based on a centre, and a from and to date",
CacheDuration = 600, MessageName = "GetStoriesForCentre")]
public XmlDataDocument GetStoriesForCentre(string centre, DateTime fromDate, DateTime toDate)
{
Database db = new Database("TarkStoriesConnectionString");