articleone : Using Blogger, XML & ASP - A How-To
I've been using Blogger for over 2 years now, and, simply put, love it. It's a very, very powerful application for something so simple. However, there were some things it couldn't do which I wanted; a lot of these could be solved by BloggerPro - but unfortunately I can't afford anything in American dollars, having to subsist on the Pacific Pesos. So I used another method of getting more out of blogger - posting everything into XML.
At first I tried the XML examples on the blogger How-To boards, but found it wouldn't work for me. So instead I set up my own structure, which has proved very versatile and stable. If you want to move to ASP & blogXML, here's a somewhat lengthy how-to based on the wrongwaygoback method of using it.
Firstly you need to know if your server can run ASP and XML. Check this out first, as by the time this is over your files will be radically different. Go! Check with your ISP now! Having done that the next step is to change your settings.
The first setting to change is Blog Filename. This needs to change to have an .xml extension. For the purpose of this how-to, we'll call it text.xml. That way you'll know text.xml = the blog text. Simple? Riiiiiiiight!
The second setting to change is FTP Archive Filename. This needs to change to have an .xml extension as well. We'll call it archive.xml. Therefore archive.xml = the list of archive pages, and xx_xx_xxxx_archive.xml = the actual blog text archived pages.
These are the only things on the settings page you need to change. But it's not over yet - we need to change the templates!
Here is the code to paste into the Template for Your Weblog. With this code, and all the others, double check for where the paragraph breaks actually are and where they appear to be in your browser:
<?xml version="1.0" encoding="iso-8859-1" ?>
<XBlog>
<Title>Your Blog's Name Here</Title>
<Blogger>
<BlogDateHeader>
<Blog>
<Date><$BlogDateHeaderDate$></Date>
</BlogDateHeader>
<Post ID="<$BlogItemNumber$>" Time="<$BlogItemDateTime$>" Author="<$BlogItemAuthorNickname$>" AuthorEmail="<$BlogItemAuthorEmail$>" PostURL="<$BlogItemArchiveFileName$>"><![CDATA[<$BlogItemBody$>]]></Post>
<BlogDateFooter>
</Blog>
</BlogDateFooter>
</Blogger>
</XBlog>
You can remove or include more <$blogger$> tags as you like into the Item tag so long as you do it in the format newtag=<$bloggertag$>. The Title tag will be filled in by the day of the post. The Item tag will be filled in by the text of your blog. The CDATA tag means you can post almost any character in that field, as well as javascript and HTML. However ASP will NOT work if posted to your weblog. You have been warned. Save those changes then click over to the archive template.
Here is the code to paste into the ARCHIVE Template for Your Weblog:
<?xml version="1.0" encoding="iso-8859-1" ?>
<XBlog>
<Blog>
<Date>Insert Archive Page Title</Date>
<Post ID="Insert ID Number Here" Time="Insert Title Here" Author="Insert your name here" AuthorEmail="Insert your e-mail address here" PostURL="/index.asp?archive.xml"> <![CDATA[<Blogger><a href="/index.asp?<$BlogArchiveLink$>"><$BlogArchiveName$></a><br /></Blogger>]]>
</Post>
</Blog>
</XBlog>
Notice all the "Insert Your X Here" statements? As the archive page does not automatically fill in the extra blogger tags, that's were you should manually insert your details. Save these changes and we're onto the next main step.
So far you've told blogger (a) that you'll be posting in XML and (b) the structure of the XML to post in. However the XML needs to be processed by an ASP page on your site. For the purposes of this how-to we will call this page index.asp. If you call it something else, such as default.asp, you will have to change there references to index.asp in the code above and below.
Whether you create your page in CSS or HTML, there are three pieces of ASP code you'll need on the page. The first piece of code sets up a routine for grabbing the XML files. Here is the first piece of ASP code you'll need to paste into the TOP of index.asp:
<%
'this code sets up a routine for grabbing the XML files
Response.ContentType = "text/html"
sub TransformXML(sXMLFilename, sXSLFilename)
dim objXMLDoc
dim objXSLDoc
'First, load the XML Document
set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXMLDoc.async = false
objXMLDoc.load(Server.MapPath(sXMLFilename))
'Now Load the XSL Document
set objXSLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXSLDoc.async = false
objXSLDoc.load(Server.MapPath(sXSLFilename))
' Now simply transform the XML/XSL files into HTML
Response.Write(objXMLDoc.transformNode(objXSLDoc))
end sub
%>
This is, essentially, a way of grabbing the XML and XSL (what's XSL you ask? wait and see!) files and munging them together to create HTML. There is nothing in this code that you need to change.
Next you need to grab the right .xml page. The second piece of ASP code you need to paste into the TOP of index.asp is as follows:
<%
'this code selects the right XML files to grab.
'Pick an XSL
sXSLFilename = "/format.xsl"
'Work out which xml sheet [blog, archive list or archive page]
If request.servervariables("query_string") <> "" then
sXMLFilename = "/" & request.servervariables("query_string")
Else
sXMLFilename = "/text.xml"
End If
%>
It grabs the appropriate page depending on a request sent to the server. By default it will grab the text.xml page (your latest blog text). If, however, you click on an archive page link (which I'll get to at the end), it will return the archive.xml page. If an weblog archive page is clicked it will return an xx_xx_xxxx_archive.xml page. You'll see how this works when we get it up and running. It will also grab the format.xsl page. I'll come to that in a minute
The third piece of ASP code basically squooshed them all together. Whilst the first two pieces of code should be pasted at the top of index.asp, this piece of code should be put where you want your weblog to sit on the page. This can be anywhere in your index.asp. The ASP code to paste is as follows:
<% 'putting it all together
TransformXML sXMLFilename, sXSLFilename
%>
Now you have a fully functional index.asp page - except for one thing. You need an .xsl sheet. What is an .xsl? It's a stylesheet to transform the XML into a browser friendly format. It MUST match certain elements of your .xml file to work. Here is a simple one which will work with our template:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="Blog">
<b><xsl:value-of select="Date"/></b><br/><br/>
<xsl:for-each select="Post">
<xsl:value-of disable-output-escaping="yes" select="."
/><br/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Save this as format.xsl on your server in the same folder as your blog. This transforms the .xml page to bold the Day (or title field) and then list all the posts under that day below it.
Using an XSL you can do heaps of things with your .xml file. You can hide all but the first post, make completely different styles for every odd post, make then appear on different layers, etc, etc. Using XSL is THE reason I changed to the XML format. I will be discussing this in a later how-to, so you can get the most out of your XML.
The last thing to do is to make sure you link to your archive list as http://www.yourdomain.com/index.asp?archive.xml. Things that will NOT work (properly) are http://www.yourdomain.com/archive.xml and http://www.yourdomain.com/archive.asp. Also double check that your weblog archive pages are being linked to as http://www.yourdomain.com/index.asp?xx_xx_xxxx_archive.xml. If they are not there is something wrong with your templates in blogger (not the ASP or XSL pages). Make sure that the templates are the same as in this how-to, not something else, and if you've changed the file paths you've done so correctly.
If it all works then you should have a fully functional weblog using ASP, XML and XSL. Huzzah!
Some caveats:
1. I have not used a DTD for the XML/XSL. This is because for a weblogger's purpose, they are something that is simply unneeded. Now, if you were going to have your weblog beamed to 20 different corporate sites, maybe you might need one. I have an initial one here, which works like this.
2. As I mentioned, ASP will not work in your blog. I've never had the need to use ASP in my blog, but maybe you do. This solution is not for you then. Move along
3. If your blog is in a different folder to the base folder, or you want to change the file name, go ahead, but make sure you check for all the references to them in the code. For instance, "/text.xml" should become "/foldername/text.xml", so on and so forth.
4. Make sure you backup all your original templates before you do this, and don't come crying to me if you fuck-up. If you want help, though, feel free to e-mail me @ wrongwaygoback.com.
Good Luck!
[this code was helped put together by Nik & Mike, lord bless their saintly little hearts]
At first I tried the XML examples on the blogger How-To boards, but found it wouldn't work for me. So instead I set up my own structure, which has proved very versatile and stable. If you want to move to ASP & blogXML, here's a somewhat lengthy how-to based on the wrongwaygoback method of using it.
Firstly you need to know if your server can run ASP and XML. Check this out first, as by the time this is over your files will be radically different. Go! Check with your ISP now! Having done that the next step is to change your settings.
The first setting to change is Blog Filename. This needs to change to have an .xml extension. For the purpose of this how-to, we'll call it text.xml. That way you'll know text.xml = the blog text. Simple? Riiiiiiiight!
The second setting to change is FTP Archive Filename. This needs to change to have an .xml extension as well. We'll call it archive.xml. Therefore archive.xml = the list of archive pages, and xx_xx_xxxx_archive.xml = the actual blog text archived pages.
These are the only things on the settings page you need to change. But it's not over yet - we need to change the templates!
Here is the code to paste into the Template for Your Weblog. With this code, and all the others, double check for where the paragraph breaks actually are and where they appear to be in your browser:
<?xml version="1.0" encoding="iso-8859-1" ?>
<XBlog>
<Title>Your Blog's Name Here</Title>
<Blogger>
<BlogDateHeader>
<Blog>
<Date><$BlogDateHeaderDate$></Date>
</BlogDateHeader>
<Post ID="<$BlogItemNumber$>" Time="<$BlogItemDateTime$>" Author="<$BlogItemAuthorNickname$>" AuthorEmail="<$BlogItemAuthorEmail$>" PostURL="<$BlogItemArchiveFileName$>"><![CDATA[<$BlogItemBody$>]]></Post>
<BlogDateFooter>
</Blog>
</BlogDateFooter>
</Blogger>
</XBlog>
You can remove or include more <$blogger$> tags as you like into the Item tag so long as you do it in the format newtag=<$bloggertag$>. The Title tag will be filled in by the day of the post. The Item tag will be filled in by the text of your blog. The CDATA tag means you can post almost any character in that field, as well as javascript and HTML. However ASP will NOT work if posted to your weblog. You have been warned. Save those changes then click over to the archive template.
Here is the code to paste into the ARCHIVE Template for Your Weblog:
<?xml version="1.0" encoding="iso-8859-1" ?>
<XBlog>
<Blog>
<Date>Insert Archive Page Title</Date>
<Post ID="Insert ID Number Here" Time="Insert Title Here" Author="Insert your name here" AuthorEmail="Insert your e-mail address here" PostURL="/index.asp?archive.xml"> <![CDATA[<Blogger><a href="/index.asp?<$BlogArchiveLink$>"><$BlogArchiveName$></a><br /></Blogger>]]>
</Post>
</Blog>
</XBlog>
Notice all the "Insert Your X Here" statements? As the archive page does not automatically fill in the extra blogger tags, that's were you should manually insert your details. Save these changes and we're onto the next main step.
So far you've told blogger (a) that you'll be posting in XML and (b) the structure of the XML to post in. However the XML needs to be processed by an ASP page on your site. For the purposes of this how-to we will call this page index.asp. If you call it something else, such as default.asp, you will have to change there references to index.asp in the code above and below.
Whether you create your page in CSS or HTML, there are three pieces of ASP code you'll need on the page. The first piece of code sets up a routine for grabbing the XML files. Here is the first piece of ASP code you'll need to paste into the TOP of index.asp:
<%
'this code sets up a routine for grabbing the XML files
Response.ContentType = "text/html"
sub TransformXML(sXMLFilename, sXSLFilename)
dim objXMLDoc
dim objXSLDoc
'First, load the XML Document
set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXMLDoc.async = false
objXMLDoc.load(Server.MapPath(sXMLFilename))
'Now Load the XSL Document
set objXSLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
objXSLDoc.async = false
objXSLDoc.load(Server.MapPath(sXSLFilename))
' Now simply transform the XML/XSL files into HTML
Response.Write(objXMLDoc.transformNode(objXSLDoc))
end sub
%>
This is, essentially, a way of grabbing the XML and XSL (what's XSL you ask? wait and see!) files and munging them together to create HTML. There is nothing in this code that you need to change.
Next you need to grab the right .xml page. The second piece of ASP code you need to paste into the TOP of index.asp is as follows:
<%
'this code selects the right XML files to grab.
'Pick an XSL
sXSLFilename = "/format.xsl"
'Work out which xml sheet [blog, archive list or archive page]
If request.servervariables("query_string") <> "" then
sXMLFilename = "/" & request.servervariables("query_string")
Else
sXMLFilename = "/text.xml"
End If
%>
It grabs the appropriate page depending on a request sent to the server. By default it will grab the text.xml page (your latest blog text). If, however, you click on an archive page link (which I'll get to at the end), it will return the archive.xml page. If an weblog archive page is clicked it will return an xx_xx_xxxx_archive.xml page. You'll see how this works when we get it up and running. It will also grab the format.xsl page. I'll come to that in a minute
The third piece of ASP code basically squooshed them all together. Whilst the first two pieces of code should be pasted at the top of index.asp, this piece of code should be put where you want your weblog to sit on the page. This can be anywhere in your index.asp. The ASP code to paste is as follows:
<% 'putting it all together
TransformXML sXMLFilename, sXSLFilename
%>
Now you have a fully functional index.asp page - except for one thing. You need an .xsl sheet. What is an .xsl? It's a stylesheet to transform the XML into a browser friendly format. It MUST match certain elements of your .xml file to work. Here is a simple one which will work with our template:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="Blog">
<b><xsl:value-of select="Date"/></b><br/><br/>
<xsl:for-each select="Post">
<xsl:value-of disable-output-escaping="yes" select="."
/><br/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Save this as format.xsl on your server in the same folder as your blog. This transforms the .xml page to bold the Day (or title field) and then list all the posts under that day below it.
Using an XSL you can do heaps of things with your .xml file. You can hide all but the first post, make completely different styles for every odd post, make then appear on different layers, etc, etc. Using XSL is THE reason I changed to the XML format. I will be discussing this in a later how-to, so you can get the most out of your XML.
The last thing to do is to make sure you link to your archive list as http://www.yourdomain.com/index.asp?archive.xml. Things that will NOT work (properly) are http://www.yourdomain.com/archive.xml and http://www.yourdomain.com/archive.asp. Also double check that your weblog archive pages are being linked to as http://www.yourdomain.com/index.asp?xx_xx_xxxx_archive.xml. If they are not there is something wrong with your templates in blogger (not the ASP or XSL pages). Make sure that the templates are the same as in this how-to, not something else, and if you've changed the file paths you've done so correctly.
If it all works then you should have a fully functional weblog using ASP, XML and XSL. Huzzah!
Some caveats:
1. I have not used a DTD for the XML/XSL. This is because for a weblogger's purpose, they are something that is simply unneeded. Now, if you were going to have your weblog beamed to 20 different corporate sites, maybe you might need one. I have an initial one here, which works like this.
2. As I mentioned, ASP will not work in your blog. I've never had the need to use ASP in my blog, but maybe you do. This solution is not for you then. Move along
3. If your blog is in a different folder to the base folder, or you want to change the file name, go ahead, but make sure you check for all the references to them in the code. For instance, "/text.xml" should become "/foldername/text.xml", so on and so forth.
4. Make sure you backup all your original templates before you do this, and don't come crying to me if you fuck-up. If you want help, though, feel free to e-mail me @ wrongwaygoback.com.
Good Luck!
[this code was helped put together by Nik & Mike, lord bless their saintly little hearts]