Created
January 18, 2016 11:07
-
-
Save miklund/e642f787e125905a04da to your computer and use it in GitHub Desktop.
2016-01-18 Exporting comments from Orchard CMS to import them into Disqus - Part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Exporting comments from Orchard CMS to import them into Disqus - Part 2 | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2016/01/18/exporting-comments-from-orchard-cms-to-import-them-into-disqus-part-2.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ArrayOfComment xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | |
<Comment> | |
<Author>Mikael Lundin</Author> | |
<CommentDateUtc>2013-06-08 12:43:42</CommentDateUtc> | |
<Email i:nil="true" /> | |
<Id>16</Id> | |
<PostLink>http://blog.mikaellundin.name/2013/06/08/test-post.html</PostLink> | |
<PostPublishUtc>2013-06-08 12:43:23</PostPublishUtc> | |
<PostSlug>test-post</PostSlug> | |
<PostText><![CDATA[<p>Test</p>]]></PostText> | |
<PostTitle>Test post</PostTitle> | |
<SiteName i:nil="true" /> | |
<Text><![CDATA[Test comment]]></Text> | |
</Comment> | |
</ArrayOfComment> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dsq="http://www.disqus.com/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.0/"> | |
<channel> | |
<item> | |
<title>Test post</title> | |
<link>http://blog.mikaellundin.name/2013/06/08/test-post.html</link> | |
<content:encoded><![CDATA[<p>Test</p>]]></content:encoded> | |
<dsq:thread_identifier>test-post</dsq:thread_identifier> | |
<wp:post_date_gmt>2013-06-08 12:43:23</wp:post_date_gmt> | |
<wp:comment_status>open</wp:comment_status> | |
<wp:comment> | |
<wp:comment_id>16</wp:comment_id> | |
<wp:comment_author>Mikael Lundin</wp:comment_author> | |
<wp:comment_author_email></wp:comment_author_email> | |
<wp:comment_author_url></wp:comment_author_url> | |
<wp:comment_author_IP /> | |
<wp:comment_date_gmt>2013-06-08 12:43:42</wp:comment_date_gmt> | |
<wp:comment_content><![CDATA[Test comment]]></wp:comment_content> | |
<wp:comment_approved>1</wp:comment_approved> | |
<wp:comment_parent>0</wp:comment_parent> | |
</wp:comment> | |
</item> | |
</channel> | |
</rss> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// transform input xml to output xml using the transformation xsl file | |
// transform: string -> string -> string -> unit | |
let transform (inputFile : string) (transformFile : string) (outputFile : string) = | |
// make sure output is indented, human readable | |
let writerSettings = new System.Xml.XmlWriterSettings(Indent = true) | |
// create output xml file | |
let outputWriter = System.Xml.XmlWriter.Create(outputFile, writerSettings) | |
// create a transformer with debug option enabled | |
let transformer = System.Xml.Xsl.XslCompiledTransform(enableDebug = true) | |
// settings of transformation will disallow functions and scripts | |
let settings = System.Xml.Xsl.XsltSettings(enableDocumentFunction = false, enableScript = false) | |
// load the xsl stylesheet | |
transformer.Load(System.Xml.XmlReader.Create(transformFile), settings, null) | |
// transform input file and write result to output file | |
transformer.Transform(System.Xml.XmlReader.Create(inputFile), outputWriter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:dsq="http://www.disqus.com/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:wp="http://wordpress.org/export/1.0/"> | |
<xsl:output method="xml" indent="yes"/> | |
<xsl:template match="/"> | |
<rss version="2.0" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:dsq="http://www.disqus.com/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:wp="http://wordpress.org/export/1.0/"> | |
<channel> | |
<xsl:apply-templates select="ArrayOfComment/Comment" /> | |
</channel> | |
</rss> | |
</xsl:template> | |
<xsl:template match="Comment"> | |
<item> | |
<!-- title of article --> | |
<title><xsl:value-of select="PostTitle"/></title> | |
<!-- absolute URI to article --> | |
<link><xsl:value-of select="PostLink"/></link> | |
<!-- body of the page or post; use cdata; html allowed (though will be formatted to DISQUS specs) --> | |
<content:encoded><xsl:value-of select="PostText" disable-output-escaping="yes"/></content:encoded> | |
<!-- value used within disqus_identifier; usually internal identifier of article --> | |
<dsq:thread_identifier><xsl:value-of select="PostSlug"/></dsq:thread_identifier> | |
<!-- creation date of thread (article), in GMT. Must be YYYY-MM-DD HH:MM:SS 24-hour format. --> | |
<wp:post_date_gmt><xsl:value-of select="PostPublishUtc"/></wp:post_date_gmt> | |
<!-- open/closed values are acceptable --> | |
<wp:comment_status>open</wp:comment_status> | |
<wp:comment> | |
<!-- internal id of comment --> | |
<wp:comment_id><xsl:value-of select="Id"/></wp:comment_id> | |
<!-- author display name --> | |
<wp:comment_author><xsl:value-of select="Author"/></wp:comment_author> | |
<!-- author email address --> | |
<wp:comment_author_email><xsl:value-of select="Email"/></wp:comment_author_email> | |
<!-- author url, optional --> | |
<wp:comment_author_url><xsl:value-of select="SiteName"/></wp:comment_author_url> | |
<!-- author ip address --> | |
<wp:comment_author_IP></wp:comment_author_IP> | |
<!-- comment datetime, in GMT. Must be YYYY-MM-DD HH:MM:SS 24-hour format. --> | |
<wp:comment_date_gmt><xsl:value-of select="CommentDateUtc"/></wp:comment_date_gmt> | |
<!-- comment body; use cdata; html allowed (though will be formatted to DISQUS specs) --> | |
<wp:comment_content><xsl:value-of select="Text" disable-output-escaping="yes"/></wp:comment_content> | |
<!-- is this comment approved? 0/1 --> | |
<wp:comment_approved>1</wp:comment_approved> | |
<!-- parent id (match up with wp:comment_id) --> | |
<wp:comment_parent>0</wp:comment_parent> | |
</wp:comment> | |
</item> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment