我需要从我的数据库为谷歌创建一个站点地图xml,并使用C#将其存储在服务器上。这就是我到目前为止所做的一切..(帮助我如何检索这个xml文件并使用c#在文件名xxxx.xml上存储在服务器上)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[SitemapXML]
(@url NVARCHAR(500) = '', )
AS
BEGIN
WITH XMLNAMESPACES
(
DEFAULT 'http://www.sitemaps.org/schemas/sitemap/0.9'
)
SELECT
@url + '/default.aspx?page=' + CAST(a.id AS NVARCHAR(10)) AS 'location',
CONVERT(NVARCHAR(30), a.page_date, 110) AS 'lastmodified',
FROM
tbl_mytable a WITH (NOLOCK)
FOR XML PATH('url'), ROOT('urlroot')
END
但这是读取非常少的页面,其中的url进入xml并在id为10的中间打破。并且没有正确关闭xml标记。请帮忙。
由于
这是输出:
<urlroot xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><location>xxx.com/default.aspx?page=1</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=2</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=3</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=4</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=5</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=6</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=7</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=8</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=9</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=10</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=11</location><lastmod>01-01-2012</lastmod></url>
<url><location>xxx.com/default.aspx?page=12</location><lastmod>01-01-2012</lastmod>
它在第12页打破,但我在数据库表中有这么多页面。