PostgreSQL 生成 XML 网站地址

PostgreSQL XML 网站地图 About 1,131 words

XML 相关函数简介

xmlroot

xml头部信息

xmlconcat

拼接xml类型元素

xmlelement

组成xml类型元素

xmlforest

生成一组xml类型的元素集合,类型为:xmlforest

xmlagg

集合xml,可以将xmlforest聚合为一个xml元素

网站地图实例

https://www.zhangbj.com/sitemap.xml

select
xmlroot(
    xmlelement(name urlset, xmlattributes('http://www.sitemaps.org/schemas/sitemap/0.9' as xmlns),
        xmlconcat(
            xmlelement(name url, 
                xmlelement(name loc, 'http://localhost'),
                xmlelement(name lastmod, current_date),
                xmlelement(name changefreq, 'always'),
                xmlelement(name priority, 1)
            ),
            xmlagg(
                xmlelement(name url,
                    xmlforest(concat('http://localhost/p/',id,'.html') as loc),
                    xmlelement(name lastmod, current_date),
                    xmlelement(name changefreq, 'daily'),
                    xmlelement(name priority, 0.8)
                )
            order by create_ts desc)
        )
    )
    ,version '1.0', standalone yes)::text as sitemap
from post where post_status = 0

备注

PostgreSQL编译安装时需指定--with-libxml

代码

https://github.com/fendoudebb/z-blog-openresty

Views: 2,500 · Posted: 2020-03-13

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh