Using TidyATL in VBScript (or basic COM for web developers)

clock December 30, 2010 03:54 by author Dan

As part of a request to check an XML file to make sure it was correctly formatted, I decided to leverage HTMLTidy within VBScript. The best article I found that referenced using the COM/ATL wrapper for the library. However, that article was for .NET and since I was working on a plugin for the RedDot CMS, I wanted to keep with using VBScript to accomplish the task. Also, I'm a bit of a novice at referencing COM components via VBscript, so it was a good learning experience overall.

  1. First off, you will need to download the COM/ATL wrapper from this location: http://users.rcn.com/creitzel/tidy/TidyATL.zip and extract this on your machine (or server)
  2. Then, you will need to register the TidyATL.dll file using regsvr32. The command I used was:
    regsvr32 /c c:\Tools\TidyATL.dll

Then, knowing very little about the API of this DLL and finding little online about it, I stumbled across this help page that describes using the OLE/COM: http://msdn.microsoft.com/en-us/library/d0kh9f4c(v=vs.80).aspx

Using the OLE/COM Object viewer I was able to locate the TidyDocument class that you register with the command above and get a look at the methods it exposed.

This gives us a listing of the methods available within the library, so from there with a little trial and error, you can begin to piece together how to use the library. I recommend creating a tidy config file when using the library because otherwise you have to use the SetOptValue method and then look up the integer for each of the tidy options which would get pretty annoying. Here's the config file I used just for basic HTML formatting:

// sample config file for HTML tidy
indent: auto
indent-spaces: 2
wrap: 72
markup: yes
output-xml: no
input-xml: no
show-warnings: yes
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
break-before-br: no
uppercase-tags: no
uppercase-attributes: no
char-encoding: latin1
new-inline-tags: cfif, cfelse, math, mroot, 
  mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
  munder, mover, mmultiscripts, msup, msub, mtext,
  mprescripts, mtable, mtr, mtd, mth
new-blocklevel-tags: cfoutput, cfquery
new-empty-tags: cfelse

Then, here is the VBScript code to process a file using the library:

set TidyDocument=Server.CreateObject("Tidy.Document")
TidyDocument.LoadConfig(Server.MapPath("tidy.config"))
TidyDocument.SetErrorFile(Server.MapPath("errors.txt"))
If TidyDocument.ParseFile(Server.MapPath("file.htm")) < 0 Then
	Response.Write "Error parsing file, check errors file"
Else
	errCode = TidyDocument.CleanAndRepair()
	If errCode < 0 Then
		Response.Write "Error cleaning/repairing file, check errors file"
	Else
		Response.Write TidyDocument.SaveString()
	End If
End If

I wasn't able to get the OnMessage event wired up to an event handler in VBScript. I tried following the steps listed here: http://msdn.microsoft.com/en-us/library/ms974564 to no avail on my XP development machine. If you are reading this and have gotten the event handler function working for the TidyATL, please drop me a line in the comments.

SiteCatalyst Generic Event Tracking Function

clock December 17, 2010 07:09 by author Dan

Tracking links or events in SiteCatalyst that don't correspond to a page view is not exactly spelled out in their documentation, so I compiled a function that can be used to easily do this.

The format for SiteCatalyst event calls is:

var eventName = "Report Click";
//add the name of your report suite
s=s_gi('reportSuiteName');
//add the name of the eVar or prop variables you want to trigger, 
//include "events" if an event will also be fired
s.linkTrackVars= 'propX,eVarX,events'; 
// add the specific event here
s.linkTrackEvents= 'eventX'; 
s.prop7 = eventName;
s.eVar7 = eventName;
//add the specific event here too
s.events = 'event7'; 
//call the .tl() method
s.tl(this,'o', eventName);

Having created several specific functions for these, it made much more sense to encapsulate this into one function that would work for all types of events I would be calling.

var SiteCatalyst = {};
SiteCatalyst.reportSuite = 'reportSuite';
SiteCatalyst.registerEvent = function(eventDetails){
        //if the s_code library was not included, don't throw an error
	if (s === undefined)
		return;
	s=s_gi(this.reportSuite);
	var linkTrackVars = [];
	if (eventDetails.events !== undefined && eventDetails.events.length > 0)
	{
		s.linkTrackEvents = eventDetails.events;
		s.events = eventDetails.events;
		linkTrackVars.push("events");
	}
	if (eventDetails.eVars !== undefined && eventDetails.eVars.length > 0)
	{
		var evars = eventDetails.eVars.split(",");
		for (var e in evars)
		{
			s[evars[e]] = eventDetails.title ;
			linkTrackVars.push(evars[e]);
		}
	}
	s.linkTrackVars = linkTrackVars.join();
	s.tl(this,'o',eventDetails.title);
	return;
};

Then, you can bind SiteCatalyst events to your DOM events using jQuery or your library of choice:

$("#loginButton").click(
	SiteCatalyst.registerEvent(
		{
			events:'eventX,eventY',
			eVars:'eVarX,propY',
			title:'Login Button'
		})
);

Debugging these types of event calls will not work through the SiteCatalyst debugger so you will need to use your favorite web debugging proxy in order to check that it is actually working.

Some HTML5 Experiments

clock December 8, 2010 08:43 by author Dan

Just a few very simple experiments adapted from HTML5: Up and Running.

MySql.Data Information for BlogEngine.NET

clock December 7, 2010 02:10 by author Dan

I'm using the MySql data provider for BlogEngine.NET and ran into a small issue when trying to get it up and running.

The BlogEngine.NET 1.6 MySQLWeb.Config references the MySql.Data assembly version 6.2.2.0. I was unable to find that as one of the versions on the MySql Connector for .NET pages. All you will need to do is update the version in the web.config file to match the one in the latest version of the connector in both spots.

<add assembly="MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>

and then in:

	<system.data>
		<DbProviderFactories>
			<clear/>
			<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.2.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
		</DbProviderFactories>
	</system.data>

Hello World!

clock December 5, 2010 19:00 by author Dan

After a long hiatus, I'm putting my BlogEngine.NET hosted blog back online so I can start cataloging those fixes I come across in hopes that someone else out there may find them valuable. After all, that's how I find the answers to many of my puzzling problems (looking at you, SharePoint). 

This is a customized theme that I developed using the 960 grid system, Cufon and the free and very cool Comfortaa font. I'll be packaging it up for download once I complete all of the tweaks to the different pages.