博客园备份档案浏览的小工具

最近才发现博客园提供了一个功能,就是可以根据时间对博客进行备份。如下图所示

http://www.cnblogs.com/chenxizhang/admin/BlogBackup.aspx 【是在管理页面中】

image

备份操作会得到一个XML文件,其实就是标准的RSS格式的。我们可以大致看一下内容

image

但这样看总是有些不方便的,为此我简单地写了一个小工具,它可以查看这些文件,就如在网上看到的一样

image

其实这个工具,谁都能写出来的。我就是用了一个xslt文件将那个xml文件转换为了Html文件,然后显示出来而已。

xslt文件的内容大致如下

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="html" indent="yes"/>
  <xsl:template match="rss">
    <html>
      <head>
        <title>
          <xsl:value-of select="channel/title"/>
        </title>
      </head>
      <body>
        <h1>
          <xsl:value-of select="channel/title"/>
        </h1>
        <xsl:for-each select="channel/item">
          <h2>
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="link"/>
              </xsl:attribute>
              <xsl:value-of select="title"/>
            </a>
          </h2>
          <font size="2">
            <xsl:value-of disable-output-escaping="yes" select="description"/>
          </font>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

窗体代码如下

using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Xsl;

namespace BlogViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "XML 文件(*.XML)|*.Xml";
            dialog.InitialDirectory = Application.StartupPath;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string inputFile = dialog.FileName;
                string outputFile = System.IO.Path.GetFileNameWithoutExtension(inputFile) + ".html";

                XslTransform tran = new XslTransform();

                string resourceName = "BlogViewer.BlogRss.xslt";
                System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
                XmlReader reader = XmlReader.Create(stream);
                tran.Load(reader);
                reader.Close();
                tran.Transform(inputFile, outputFile);
                this.webBrowser1.Url = new Uri(Application.StartupPath+"\\"+outputFile);
            }

        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

该工具很简单,有兴趣的朋友可以继续添加一些功能。例如编写更加合适的xslt文件,或者实现其他的管理功能。

当前博客园仅提供了备份功能,不知道以后会不会提供还原的功能。

该小工具我打包放在下面,如果有需要的朋友可以直接下载

BlogViewer.rar

posted @ 2008-08-17 15:42  陈希章  阅读(778)  评论(1编辑  收藏  举报