Sina2WordPress的第一步——解析WXR文件格式
WXR是Wordpress eXtended Rss的缩写,是WordPress针对博客信息特意设定的格式,它最大的优点是兼容性好,包含信息丰富
通过参照导出的文件,初步找到一个完备集(见下方代码),经测试在WP无任何内容情况下无信息缺漏错误现象
下方代码已经尽可能的注释了所有可能的标签和属性,并且由于一些标签和属性与Sina2WordPress关系不大,故未深究
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
< ?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> |
很有用,谢谢~