Category Archives: xml

.Net Development – XslCompiledTransform with XMLWriter ignores output method

As XslTransform is now obsolete, I now use XslCompiledTransform to transform my XML and XSLT documents. When transforming I want an XmlDocument returned so that I can further manipulate the output, to achieve this I use XMLWriter but for some unknown and baffling reason XMLWriter does not respect the ouput method of the XSL document and will ALWAYS give you XML and by XML I mean closing self closing tags etc. which is no good when you’re outputting HTML with textarea, link and script elements. I hate to do it but the only way to be confident of correct output was to parse the output string and replace these elements using a beefy regular expression. Does anyone else know how to force XHTML or even HTML output when using XMLWriter and XslCompiledTransform. I’ve given up looking.

Web Application installations with Wix…. Awesome

This week I set off with the goal of making one of our web applications alot easier to deploy. The tools I chose were –

  1. Web Application Installer (WAI)
  2. Wix (Windows Installer XML)
  3. WixEdit

I’d played with all three before but never really got past prototype stage. I’ve spent the last day learning wix and all the elements relevant to me. The Web Application Installer is collection of scripts and a template for different types of web applications. Firstly you use WAI to generate a list of files to install and the use WixEdit to edit that list and many other properties of the wix installation. Once happy with the configuration of the installation WixEdit will generate an msi for installation on your target machine. They truly are an excellent collection of tools. I now have an msi installer that sets up a web site in IIS, sets the ASP.NET version to 2, sets all the required permissions, creates a DB in SQL Server Express (specifying where to save the mdf and ldf files too) and changes the connection string in web.config accordingly. Todays quota of job satisfaction has now been achieved – saving about an hour per install (I’ve to install this app 28 times for different clients so the work was definitely worth while).

One huge pit fall which made me silly amounts of angry was that the SQL script you use to generate the tables and initial data for your database MUST be saved in Unicode (UTF-8). If it’s not then wix won’t be able to read it. I lost 3 hours yesterday with this!!!! as SQL server management studio express by default saves to UCS-2 Big Endian. Very little documentation on this fact so hopefully this post will help a little.

Extend Your Browser

Tuesday 6th (the day of my presentation) eventually rolled around. Due to a crazy machine rebuild and re-install fest, I only finished writing the presentation at 1:30pm on the day. It went really well, some very good questions at the end. As I mentioned in my previous entry – the description of the presentation was –

Firefox and the Gecko family of browsers are not simply web browsers, they can be extended to provide custom functionality, and used as platforms for building standalone applications. During the presentation I will discuss the anatomy of the Gecko engine and the Firefox browser, extensions and how to create an extension for the Firefox 2.0 browser using Aggreg8 (http://aggreg8.mozdev.org ) as an example.

Philip is a 2003 Software Engineering graduate of Dublin City University. He has been working at Karova Ltd for two years, on ecommerce and custom web applications, and now holds the position of Senior Developer. Outside the office, he hacks on Firefox extensions and small Python or Perl based open source projects. He loves C#, XSLT, Python, MySQL, WxPython, SVG, XUL, Gecko, Javascript, RSS, CSS, his Labrador puppy, Ubuntu and Mono.

You can now download my preentation-

In MP3 audio format – (no pen clicking this time 🙂 )
ITWalesExtendingYourBrowserPhilipRoche.MP3 [mp3 31 MB – 1 hour 2 minutes]
PDF of my presentation slides
ExtendingYourBrowser-Slides.pdf [pdf 501 KB]
PDF of my presentation slides – including my notes
ExtendingYourBrowser-Notes.pdf [pdf 548 KB]

Enjoy

Aggreg8 lives

This weekend I have gone on an all out Open Source offensive. I have released a new version of ACR (Automatically Create Rewriterules) with some bug fixes and faster processing of sites. I have released an updated version of PEA (Photoshop Elements Album Export) with improved accessibility and more options in the python script header.

Aggreg8 lives again I also started work on Aggreg8 again. I have a working version for Firefox 2.0 (not released yet) which will be my basis for my future plans.

  • Get Aggreg8 working on Firefox 2.0 – Done but not released
  • Get auto-subscribe working – Done but not released
  • Use built in Feed parser
  • Use SQLite for storage
  • Have an options panel
  • Ability to import and export OPML
  • Clean up XULs and Javascripts – especially the location of some functions
  • Add license to header of each file (MPL)
  • Create some nicer CSS stylesheets
  • Create a Norwegian language file
  • Change all references of Aggreg8.net (now a microsoft portal) to Aggreg8.org
  • Implement some sort of caching (although the aim of Aggreg8 is to be simple – caching might be overkill)

After 3 years of inactivity on the aggreg8.mozdev.org site. I am again on the active projects list and am raring to go with the above features. The aim of Aggreg8 version 0.3 is to be a super simple RSS reader with no fancy feature, just an easy way to read your RSS feeds. Using SQLite and the built in parser, I hope will improve performance too.

auto rewrite rules and google sitemap generation

Although we’re very busy in work at the moment, the last few evenings I have been pythoning myself up and have come up with 3 nifty little scripts.

Usage of all three is quite simple –

python scriptName.py http://www.karova.com

There is also a zip archive for download. As you can see I have started using Google Code project hosting. It suits my needs perfectly as it’s simple to use and the SVN server they are using is hellish quick. I’ve named the project acr (Auto Create RewriteRules). For a sample of output see http://www.karova.com/sitemap.xml . The rewrite rules was written as a personal project but also for KarovaStore – So expect release 2.1 to have clean urls and auto google sitemaps.

Update:

Yes I know Google have their own sitemap generator but mine is alot easier to use.

C# XML encoding woes

I have a simple XML document fragment with a euro symbol in it:
[code lang=”xml”]

Lorem ipsˆum dolor sit amet,

[/code]

which I want to load into an XML document.

[code lang=”cpp”]
System.Xml.XmlDocument doc=new System.Xml.XmlDocument();
doc.LoadXml(xml);
[/code]

I then output the XML of that doc to see that all is well – alas it is not, It has decided to re-enocde my beautiful numeric entities.
[code lang=”xml”]

Lorem ips€um dolor sit amet,

[/code]

I cannot find a way around this. It still works well, but god damnit . I want my bloody entity references back you bastards. Can anyone please help me. I have tried XMLTextReader and XML streams and all sorts of other google groups induced madness.

Update:

I managed to figure out a way to re-encode the data after it has been loaded into xml (after it has been xslt transformed or just as a string)-
[code lang=”cpp”]
System.Xml.XmlDocument docOut=new System.Xml.XmlDocument();
docOut.LoadXml(xml);
string text = docOut.OuterXml.ToString();

System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length);
foreach (char c in text)
{
if (c > 0x0080)
{
sb.Append(“&#”);
sb.Append((int)c);
sb.Append(‘;’);
}
else
{
sb.Append(c);
}
}
Log.logError(” sb.ToString(); = “+sb.ToString()+”\n”);

System.IO.StreamWriter sw = System.IO.File.CreateText(outXMLFile);
sw.Write(sb.ToString());
sw.Flush();
sw.Close();

//docOut.Save(outXMLFile);
[/code]

I’m not too sure but there might be a way to override the OuterXML property of the XMLDocument class. I hope so. For now it works and I am chuffed -now to get back to what weekends are really for, laundry and cleaning drinking 🙂

Dev crazy

In an attempt to vary the type of programming I am doing, out of office I have been working on quite a few cool projects. Outlined a few below – unfortunately none are for download yet as they are still in progress.

KarovaDev Firefox extension
As Karova‘s main product is a hosted e-commerce solution, we naturally have to integrate with quite a few payment service providers. It can be a chore to test our stores with these payment service providers, having to enter dummy or real credit card details everytime. I hate monkey work so I wrote a firefox extension for the Karova developers to help in the testing of Karova stores. It’s pretty sweet, You can edit all the default data passed for each payment service providers, specify the domains or virtual directories (if installed on localhost) to test against. The final test page scans all the user’s cookies and chooses the ones that match the supplied domains etc. You can then choose your site and test to your heart’s content- saving hours of monkey work.
Screenshot of KarovaDev firefox extension
It was nice to work on a beefy extension again. It re-affirmed to me how good the Gecko/ XUL platform is.
Philroche Blog Tool
Most of the C# work I do in wrk is web applications running on IIS. I do some command line apps that run as scheduled tasks but I don’t have cause to develop any GUI apps. Microsoft released Visual Studio 2005 express so I downloaded it and gave WinForms a shot… easy peasy to get a nice GUI designed and built. I decided to write a simple RSS aggregator to see how easy it would be.
Philroche Blog tool view feed
I haven’t written the RSS parser yet but I have the tree view and the Mozilla ActiveX control working well. I could have used the built in webbrowser (IE) component but then why would I want to do that.
Philroche Blog tool make post
I wanted to see if I could integrate with the wordpress API too to make blog posts so I turned to Xstandard (the lite version). Xstandard also have a .NET component that you can use. It is really neat and you can bet your house on the markup being valid.

Visual studio 2005 express is excellent and free too (as in beer). Also checkout SQL server 2005 express which I have used on a very beefy project already and it is ace – also free (as in beer).

Mod_Python
Since having a fairly new Dell machine donated to me by my Dad I have been feverishly using Ubuntu. I have Apache and mod_python running and have a nice little app running. Mod_python as a development platform is sweet as it is not as contstrained as TurboGears or Ruby on Rails. It is very hard to debug though.

So all in all I am getting some nice variety in my dev work, I find it can sometimes get stale if you’re doing the same thing day-in day-out, especially if it involves legacy asp sites. Is there anything you guys would recommend trying out as an antidote to work work while still being dev work (if you know what I mean). I do want to look at mono and PyGTK.

Half Viking Gallery Goes Live

HalfViking.com
It’s been a while on the back burner but this weekend I went hell for leather and managed to get the necessary coding done to get Halfviking.com live.

I manage all my photos 6000+ photos in Photoshop Elements and I am very happy with how it copes but it’s web gallery export sucks ass.

What I found was that PSE stores it’s data in an Access database. I wrote (using parts and few sub routines form album2gallery) a perl script to extract the data in the DB and write it to XML.

I then wrote a wad of python to parse the XML and create a static version of the gallery you now see. Using the Python Imaging Library I also managed to resize all the images to thumbnails and larger versions. All my photos are up now…. I have nothing to hide 🙂 .

There is still a couple of hitches (some duplicate albums [now fixed :)] and it’s not browser tested and I want to add some funky javascript) but I couldn’t be arsed waiting any longer… enjoy (or not)