2

我需要从我的数据库中为 google 创建一个站点地图 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 页中断,但我在数据库表中有很多页面。

4

0 回答 0