精简WordPress eXtended Rss (WXR) 文件格式

经过N次Import和数据库清空,终于将之前的WXR文件格式的完备集简化了。

简化原则是适应Sina2WordPress项目的需要,尽可能精简文件大小,删除了导入无效的(如博客标题、博客链接等)和从新浪博客中无法获取的(如评论者的链接和IP等)信息,还有item之前的的作者、分类和标签信息。作者在导入时可以指定的,反而加上会有可能的错误,分类和标签的信息用post中的分类和标签就可以自动统计了。没想明白为什么非要单独列出来,难道是为了空的分类和标签,那还要它干嘛?

一些必不可少的标签及错误总结:
1、wxr_version,缺少会提示“missing/invalid WXR version number”的错误
2、post_id,否则只会导入第一篇文章
3、status,否则都会显示成draft
4、post_type,否则无法导入
5、comment_approved,否则无法导入

P.S.post_id的问题纠结了好久,为什么官方不好好设计一下呢?至少觉得应该在Settings设定对应的选项的……

< ?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.1/"
>
<!--RSS版本号和名字空间的扩展,以上为固定内容-->

<channel>
	<wp:wxr_version>1.1</wp:wxr_version>
	<!--WXR格式版本号-->

	<item><!--页面或者日志内容,每个为一个item-->
		<title>Title test</title>
		<!--标题-->
		<content:encoded>< ![CDATA[Content_test]]></content:encoded>
		<!--这里是正文内容-->
		<wp:post_id>1</wp:post_id>
		<!--页面或日志的序号,两者使用同一序列-->
		<wp:post_date>2002-12-21 07:59:59</wp:post_date>
		<!--发表时间-->
		<wp:comment_status>open</wp:comment_status>
		<!--评论开启情况,open / closed-->
		<wp:status>publish</wp:status>
		<!--页面或日志状态,publish / draft / pending / private-->
		<wp:post_type>post</wp:post_type>
		<!--文章类型,post / page-->
		<wp:is_sticky>0</wp:is_sticky>
		<!--文章是否置顶,0 / 1-->

		<category domain="post_tag" nicename="tag_test">< ![CDATA[Tag Test]]></category>
		<category domain="category" nicename="category_test">< ![CDATA[Category Test]]></category>
		<!--
			日志或页面的标签和分类,可多个
			domain:标签对应post_tag,分类对应category
			nicename:对应标签或分类的URL友好名称
			<![CDATA[]]>:标签或分类的显示名称
		-->

		<wp:comment><!--评论,可多个-->
			<wp:comment_id>1</wp:comment_id>
			<!--自增序号,评论专用-->
			<wp:comment_author>< ![CDATA[anonymous]]></wp:comment_author>
			<!--评论者用户名-->
			<wp:comment_date>2012-12-21 07:59:59</wp:comment_date>
			<!--评论时间-->
			<wp:comment_content>< ![CDATA[Content of Comment]]></wp:comment_content>
			<!--评论内容-->
			<wp:comment_approved>1</wp:comment_approved>
			<!--评论是否被允许-->
			<wp:comment_parent>0</wp:comment_parent>
			<!--父评论,指定所回复的评论-->
		</wp:comment>
	</item>
</channel>
</rss>

WordPress eXtended Rss (WXR)文件格式解析

Sina2WordPress的第一步——解析WXR文件格式

WXR是Wordpress eXtended Rss的缩写,是WordPress针对博客信息特意设定的格式,它最大的优点是兼容性好,包含信息丰富

通过参照导出的文件,初步找到一个完备集(见下方代码),经测试在WP无任何内容情况下无信息缺漏错误现象

下方代码已经尽可能的注释了所有可能的标签和属性,并且由于一些标签和属性与Sina2WordPress关系不大,故未深究

< ?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.1/"
>
<!--RSS版本号和名字空间的扩展,以上为固定内容-->

<channel>
	<title>Blog Title</title>
	<!--博客的标题-->
	<link>http://blog.example.com</link>
	<!--博客的链接-->
	<description>Blog Description</description>
	<!--博客的说明/副标题-->
	<pubdate>Dec, 20 Jun 2012 23:59:59 +0000</pubdate>
	<!--WXR文件生成时间-->
	<language>en</language>
	<!--博客的语言,en / zh-cn-->
	<wp:wxr_version>1.1</wp:wxr_version>
	<!--WXR格式版本号-->
	<wp:base_site_url>http://example.com</wp:base_site_url>
	<!--网站根目录地址-->
	<wp:base_blog_url>http://blog.example.com</wp:base_blog_url>
	<!--博客根目录地址-->

	<wp:author><wp:author_id>1</wp:author_id><wp:author_login>admin_test</wp:author_login><wp:author_email>admin@example.org</wp:author_email><wp:author_display_name>< ![CDATA[AdMin test]]></wp:author_display_name><wp:author_first_name>< ![CDATA[AdMin]]></wp:author_first_name><wp:author_last_name>< ![CDATA[test]]></wp:author_last_name></wp:author>
	<!--
		作者列表,可多个
		wp:author_id:自增序号
		wp:author_login:用户名
		wp:author_email:邮箱
		wp:author_display_name:显示的作者名称
		wp:author_first_name、wp:author_last_name:如字面意,可为空,但需有<![CDATA[]]>
		P.S.< ![CDATA[**]]>可以理解成强制文本转换,保留文本中所有字符,以避免非法字符对XML文件的影响(后文不再赘述)
	-->

	<wp:category><wp:term_id>1</wp:term_id><wp:category_nicename>category_test</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name>< ![CDATA[分类测试]]></wp:cat_name></wp:category>
	<!--
		分类列表,可多个
		wp:term_id:自增序号,且分类和标签用的是同一个
		wp:category_nicename:URL友好名称,作为相关URL的一部分
		wp:category_parent:父分类,无即为空
		wp:cat_name:显示的分类名称
	-->

	<wp:tag><wp:term_id>2</wp:term_id><wp:tag_slug>tag_test</wp:tag_slug><wp:tag_name>< ![CDATA[标签测试]]></wp:tag_name></wp:tag>
	<!--
		标签列表,可多个
		wp:term_id:自增序号,与标签使用同一个序列
		wp:tag_slug:URL友好名称,作为相关URL的一部分
		wp:tag_name:显示的标签名称
	-->

	<generator>http://wordpress.org/?v=3.1.3</generator><!--WXR文件生成工具的标识-->

	<item><!--页面或者日志内容,每个为一个item-->
		<title>Title</title>
		<!--标题-->
		<link>http://blog.example.com/title/</link>
		<!--URL地址-->
		<pubdate>Thu, 15 Apr 2010 23:20:03 +0000</pubdate>
		<!--发布时间-->
		<dc:creator>admin</dc:creator>
		<!--文章作者-->
		<guid isPermaLink="false">http://blog.example.com/?page_id=1</guid>
		<!--
			GUID 意为 Global Unique IDentification,即全局唯一标识
			isPermaLink="false" 指示该地址非合法URL地址的属性
		-->
		<description></description>
		<content:encoded>< ![CDATA[Content_test_1]]></content:encoded>
		<!--这里是正文内容-->
		<excerpt:encoded>< ![CDATA[]]></excerpt:encoded>
		<!--文章摘录,供RSS/Atom使用,一般为空-->
		<wp:post_id>2</wp:post_id>
		<!--页面或日志的序号,两者使用同一序列-->
		<wp:post_date>2012-12-21 07:59:5</wp:post_date>
		<!--发表时间-->
		<wp:post_date_gmt>2010-12-20 23:59:59</wp:post_date_gmt>
		<!--发表时间(GMT)-->
		<wp:comment_status>open</wp:comment_status>
		<!--评论开启情况,open / closed-->
		<wp:ping_status>closed</wp:ping_status>
		<!--Ping开启情况,open / closed-->
		<wp:post_name>blog_title</wp:post_name>
		<!--URL友好的名称-->
		<wp:status>publish</wp:status>
		<!--页面或日志状态,publish / draft / pending / private-->
		<wp:post_parent>0</wp:post_parent>
		<!--只用于页面,指示父页面的id-->
		<wp:menu_order>0</wp:menu_order>
		<!--只用与页面,作为导航时的排序权值-->
		<wp:post_type>post</wp:post_type>
		<!--文章类型,post / page-->
		<wp:post_password></wp:post_password>
		<!--文章是否加密-->
		<wp:is_sticky>0</wp:is_sticky>
		<!--文章是否置顶,0 / 1-->

		<category domain="post_tag" nicename="tag_test">< ![CDATA[Tag Test]]></category>
		<category domain="category" nicename="category_test">< ![CDATA[Category]]></category>
		<!--
			日志或页面的标签和分类,可多个
			domain:标签对应post_tag,分类对应category
			nicename:对应标签或分类的URL友好名称
			<![CDATA[]]>:标签或分类的显示名称
		-->

		<wp:postmeta><!--日志或页面的元数据,可多个-->
			<wp:meta_key>_edit_last</wp:meta_key>
			<!--元数据的关键字-->
			<wp:meta_value>< ![CDATA[1]]></wp:meta_value>
			<!--元数据对应关键字的值-->
		</wp:postmeta>

		<wp:comment><!--评论,可多个-->
			<wp:comment_id>1</wp:comment_id>
			<!--自增序号,评论专用-->
			<wp:comment_author>< ![CDATA[anonymous]]></wp:comment_author>>
			<!--评论者用户名-->
			<wp:comment_author_email>anonymous@anonymous.com</wp:comment_author_email>
			<!--评论者邮箱-->
			<wp:comment_author_url>http://blog.anonymous.com</wp:comment_author_url>
			<!--评论者链接-->
			<wp:comment_author_ip>8.8.8.8</wp:comment_author_ip>
			<!--评论者IP-->
			<wp:comment_date>2012-12-21 07:59:59</wp:comment_date>
			<!--评论时间-->
			<wp:comment_date_gmt>2012-12-20 23:59:59</wp:comment_date_gmt>
			<!--评论时间(GMT)-->
			<wp:comment_content>< ![CDATA[Content of Comment]]></wp:comment_content>
			<!--评论内容-->
			<wp:comment_approved>1</wp:comment_approved>
			<!--评论是否被允许-->
			<wp:comment_type></wp:comment_type>
			<!--评论类型,空白表示一般评论,否则会标记位pingback-->
			<wp:comment_parent>0</wp:comment_parent>
			<!--父评论,指定所回复的评论-->
			<wp:comment_user_id>0</wp:comment_user_id>
			<!--如果评论者为注册用户,这里会记录用户ID-->
		</wp:comment>
	</item>
</channel>
</rss>

参考:http://ipggi.wordpress.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/

A recommended kind of RSS solution

Today I want to recommend a kind of RSS solution and  it’s just what I use for my blog.

In this way, we will have a permanent and unique rss url. As for me, it’s http://feeds.huxuan.org/huxuan

1)Sign up as the same name for your feed in FeedSky & FeedBurner.

e.g. I have
http://feed.feedsky.com/huxuan for FeedSky &
http://feeds.feedburner.com/huxuan for FeedBurner
(I just have it for example, Please don’t subscribe my blog through this two address)

2) Use the Domain Binding Service which Feedburner & Feedsky both provide to host the feed by your own domain name

You should choose only one of the two & Feedburner is recommended absolutely
You need to create a CNAME entry in the DNS records here
More information are provided by Feedburner & Feedsky when you configure the Domain Binding Service

3) Change the feed source you didn’t choose in step 2

e.g. I choose Feedburner to create the feed, so I change the feed source of Feedsky just into http://feeds.huxuan.org/huxuan.

4)Change the default rss url of wordpress

In the header.php of theme we use, similar code can be found like this:

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="http://blog.huxuan.org/feed" />

Change the url with underline into the feed you have created.

5)Change all possible default feed url on the site

There may be many default feed url list on the site most presenting as a link of an image or some else.
Just search for it and change it!

Attention: Some Errors happen in Step 6. Ignore it now.

6)Redirect the default feed url to the new one just in case

Insert the code below to .htacess which located in the main directory
# redirect default feed url to the permanent one
Redirect /feed http://feeds.huxuan.org/huxuan

7)Now all steps is done, just share your unique & permanet feed url to your friends

if one of the two feed service providers don’t work, just change to the other one via repeating Step 2 & 3

P.S. If there’s any error or problem, please feel free to inform me of that.