<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-4530474081110248662</id><updated>2010-02-18T11:12:19.839Z</updated><title type='text'>mShed</title><subtitle type='html'>Welcome to my shed</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.mshed.co.uk/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default'/><link rel='alternate' type='text/html' href='http://www.mshed.co.uk/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Pete Shipstone</name><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4530474081110248662.post-2976622584280801794</id><published>2009-04-06T16:01:00.000+01:00</published><updated>2009-04-06T16:55:54.395+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MS SQL'/><title type='text'>Unique Column That Allows Multiple Nulls</title><content type='html'>Sometimes it may be necessary for a column to hold unique values, but still allow multiple nulls.  When this scenario occures then a Unique Index will not suffice as all values within the column MUST be unique, meaning it will only allow a single null value.  &lt;br /&gt;&lt;br /&gt;One solution is to include an INSERT, UPDATE trigger on the table that checks the value being inserted/updated to ensure it is unique, but will ignore null values.  The following trigger does the trick:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="sql"&gt;&lt;br /&gt;SET ANSI_NULLS ON&lt;br /&gt;GO&lt;br /&gt;SET QUOTED_IDENTIFIER ON&lt;br /&gt;GO&lt;br /&gt;CREATE TRIGGER [dbo].[TG_TRIGGER_NAME] ON [dbo].[TABLE_NAME]&lt;br /&gt;  FOR INSERT, UPDATE&lt;br /&gt;AS&lt;br /&gt;  BEGIN&lt;br /&gt;    SET NOCOUNT ON ;&lt;br /&gt;    IF EXISTS ( select  1&lt;br /&gt;                from    inserted AS i&lt;br /&gt;                        inner join dbo.TABLE_NAME AS t on i.[COLUMN_NAME] = t.[COLUMN_NAME]&lt;br /&gt;                group by t.[COLUMN_NAME]&lt;br /&gt;                having  count(t.[COLUMN_NAME]) &gt; 1 ) &lt;br /&gt;      BEGIN&lt;br /&gt;        ROLLBACK&lt;br /&gt;        RAISERROR ('[COLUMN_NAME] must be unique', 16, 1)&lt;br /&gt;      END&lt;br /&gt;  END&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Replace the values [TG_TRIGGER_NAME], [TABLE_NAME], [COLUMN_NAME] to match the names used within your database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4530474081110248662-2976622584280801794?l=www.mshed.co.uk' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.mshed.co.uk/feeds/2976622584280801794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.mshed.co.uk/2009/04/unique-column-that-allows-nulls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/2976622584280801794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/2976622584280801794'/><link rel='alternate' type='text/html' href='http://www.mshed.co.uk/2009/04/unique-column-that-allows-nulls.html' title='Unique Column That Allows Multiple Nulls'/><author><name>Pete Shipstone</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13959464823780675819'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4530474081110248662.post-4507408444126613466</id><published>2009-04-05T10:14:00.000+01:00</published><updated>2009-04-05T11:06:23.326+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Converting XML to CSV using C#</title><content type='html'>While messing around with C# to converting XML to another format using XSLT (XSL Transformation), I decided it would be fun to try and convert an XML file to CSV as shown (figure 1).  The C# code below is what I used to apply the XSLT:&lt;br /&gt;&lt;pre name="code" class="csharp"&gt;&lt;br /&gt;//Create a new XML document and load the XML &lt;br /&gt;fileXmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;xmlDoc.Load("cdcatalog.xml");&lt;br /&gt;&lt;br /&gt;//Create an XSLT object and load the XSLT file            &lt;br /&gt;XslCompiledTransform xslTran = new XslCompiledTransform();&lt;br /&gt;xslTran.Load("csv.xsl");&lt;br /&gt;&lt;br /&gt;// This is for generating the &lt;br /&gt;outputXmlTextWriter writer = new XmlTextWriter("cdcatalog.csv", System.Text.Encoding.UTF8);&lt;br /&gt;&lt;br /&gt;//Apply the transformation and write disk&lt;br /&gt;xslTran.Transform(xmlDoc, null, writer);&lt;br /&gt;&lt;br /&gt;//Close the writer&lt;br /&gt;writer.Close();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I thought the C# code was going to be more difficult, but it was a nice surprise to find that I only needed to write 7 lines of code. Next, I had to produce the XSLT.  This was more difficult because I wanted to include the headings at the top of the CSV file. After some research on Google, I generated the following transformation.  It is split into two parts.  The first &lt;xsl:template ....&gt; generates the headings and the second outputs a record on each line which has the fields comma delimeted with strings surrounded by speach marks:&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;&lt;br /&gt; &lt;xsl:output method='text' version='1.0' encoding='UTF-8' indent='yes'/&gt;&lt;br /&gt;&lt;br /&gt; &lt;!--Output the titles--&gt;&lt;br /&gt; &lt;xsl:template match="//*"&gt;&lt;br /&gt;  &lt;xsl:for-each select="*[1]/*"&gt;&lt;br /&gt;   &lt;xsl:value-of select="name()" /&gt;&lt;br /&gt;   &lt;xsl:if test="position() != last()"&gt;&lt;br /&gt;    &lt;xsl:value-of select="','"/&gt;&lt;br /&gt;   &lt;/xsl:if&gt;&lt;br /&gt;  &lt;/xsl:for-each&gt;&lt;br /&gt;  &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;&lt;br /&gt;  &lt;xsl:apply-templates /&gt;&lt;br /&gt; &lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;!--Output the records--&gt;&lt;br /&gt; &lt;xsl:template match="//*/*"&gt;&lt;br /&gt;  &lt;xsl:for-each select="*"&gt;&lt;br /&gt;   &lt;xsl:choose&gt;&lt;br /&gt;    &lt;xsl:when test="string(number(.)) = 'NaN'"&gt;&lt;br /&gt;     &lt;xsl:text&gt;"&lt;/xsl:text&gt;&lt;br /&gt;     &lt;xsl:value-of select="."/&gt;&lt;br /&gt;     &lt;xsl:text&gt;"&lt;/xsl:text&gt;&lt;br /&gt;    &lt;/xsl:when&gt;&lt;br /&gt;    &lt;xsl:otherwise&gt;&lt;br /&gt;     &lt;xsl:value-of select="."/&gt;&lt;br /&gt;    &lt;/xsl:otherwise&gt;&lt;br /&gt;   &lt;/xsl:choose&gt;&lt;br /&gt;   &lt;xsl:if test="position() != last()"&gt;&lt;br /&gt;    &lt;xsl:value-of select="','"/&gt;&lt;br /&gt;   &lt;/xsl:if&gt;&lt;br /&gt;  &lt;/xsl:for-each&gt;&lt;br /&gt;  &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;&lt;br /&gt; &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first record in the XML file is used to determine the titles at the top of the CSV file, this can be changed by amending the XPath used in the first &lt;xsl:for-each ....&gt;. Below is an example of some XML which the XSLT can transform into a CSV file:&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&lt;br /&gt;&lt;catalog&gt;&lt;br /&gt;        &lt;cd&gt;&lt;br /&gt;                &lt;cdtitle&gt;Empire Burlesque&lt;/cdtitle&gt;&lt;br /&gt;                &lt;artist&gt;Bob Dylan&lt;/artist&gt;&lt;br /&gt;                &lt;country&gt;USA&lt;/country&gt;&lt;br /&gt;                &lt;company&gt;Columbia&lt;/company&gt;&lt;br /&gt;                &lt;price&gt;10.90&lt;/price&gt;&lt;br /&gt;                &lt;year&gt;1985&lt;/year&gt;&lt;br /&gt;        &lt;/cd&gt;&lt;br /&gt;        &lt;cd&gt;&lt;br /&gt;                &lt;cdtitle&gt;Hide your heart&lt;/cdtitle&gt;&lt;br /&gt;                &lt;artist&gt;Bonnie Tyler&lt;/artist&gt;&lt;br /&gt;                &lt;country&gt;UK&lt;/country&gt;&lt;br /&gt;                &lt;company&gt;CBS Records&lt;/company&gt;&lt;br /&gt;                &lt;price&gt;9.90&lt;/price&gt;&lt;br /&gt;                &lt;year&gt;1988&lt;/year&gt;&lt;br /&gt;        &lt;/cd&gt;&lt;br /&gt;        &lt;cd&gt;&lt;br /&gt;                &lt;cdtitle&gt;Greatest Hits&lt;/cdtitle&gt;&lt;br /&gt;                &lt;artist&gt;Dolly Parton&lt;/artist&gt;&lt;br /&gt;                &lt;country&gt;USA&lt;/country&gt;&lt;br /&gt;                &lt;company&gt;RCA&lt;/company&gt;&lt;br /&gt;                &lt;price&gt;9.90&lt;/price&gt;&lt;br /&gt;                &lt;year&gt;1982&lt;/year&gt;&lt;br /&gt;        &lt;/cd&gt;&lt;br /&gt;&lt;/catalog&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For the XSLT to work the XML needs to be in a rigid format like above.  If you would like to use it for any of your projects then it may be nesessary to change the XPath conditions so that it matches your XML files. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_clRkdFNwbPo/SdiB1Gmr_NI/AAAAAAAAAFk/pzTGqEmzFQM/s1600/csvexample.gif" class="lightbox"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 43px;" src="http://2.bp.blogspot.com/_clRkdFNwbPo/SdiB1Gmr_NI/AAAAAAAAAFk/pzTGqEmzFQM/s320/csvexample.gif" border="0" alt="CSV produced by script" id="BLOGGER_PHOTO_ID_5321145709044169938" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;NOTE: the "title" title will actually be "cdtitle"&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Thats all folks!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4530474081110248662-4507408444126613466?l=www.mshed.co.uk' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.mshed.co.uk/feeds/4507408444126613466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.mshed.co.uk/2009/04/converting-xml-to-csv-using-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/4507408444126613466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/4507408444126613466'/><link rel='alternate' type='text/html' href='http://www.mshed.co.uk/2009/04/converting-xml-to-csv-using-c.html' title='Converting XML to CSV using C#'/><author><name>Pete Shipstone</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13959464823780675819'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_clRkdFNwbPo/SdiB1Gmr_NI/AAAAAAAAAFk/pzTGqEmzFQM/s72-c/csvexample.gif' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4530474081110248662.post-7388869319575138984</id><published>2009-04-05T09:49:00.002+01:00</published><updated>2009-05-10T07:37:13.877+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Alton Towers'/><title type='text'>Cork Screw At Alton Towers</title><content type='html'>Not sure why I had this picture on my hard drive but thought somebody may be interested in it :-) so here it is:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_clRkdFNwbPo/SdhwtuMDJrI/AAAAAAAAAFU/jAEoZyEuqzQ/s1600/corkscrew.jpg" rel="superbox[image]"&gt;&lt;br /&gt;&lt;img src="http://4.bp.blogspot.com/_clRkdFNwbPo/SdhwtuMDJrI/AAAAAAAAAFU/jAEoZyEuqzQ/s320/corkscrew.jpg" width="72" height="72" alt="" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This was one of the first roller coasters I ever went on and thought it was fab,  it's such a shame that it is no longer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4530474081110248662-7388869319575138984?l=www.mshed.co.uk' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.mshed.co.uk/feeds/7388869319575138984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.mshed.co.uk/2009/04/cork-screw-at-alton-towers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/7388869319575138984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/7388869319575138984'/><link rel='alternate' type='text/html' href='http://www.mshed.co.uk/2009/04/cork-screw-at-alton-towers.html' title='Cork Screw At Alton Towers'/><author><name>Pete Shipstone</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13959464823780675819'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_clRkdFNwbPo/SdhwtuMDJrI/AAAAAAAAAFU/jAEoZyEuqzQ/s72-c/corkscrew.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4530474081110248662.post-926883171178940182</id><published>2009-04-05T08:58:00.004+01:00</published><updated>2009-05-10T07:37:48.071+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Orbs Phenomenon'/><title type='text'>An Orb In My Lounge!</title><content type='html'>While looking at a few photographs I have taken, I've noticed that I have captured an orb in my lounge.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_clRkdFNwbPo/Sdh1KyONp0I/AAAAAAAAAFc/_UHRGRRPtgo/s1600/orb02.jpg" rel="superbox[image]"&gt;&lt;br /&gt;&lt;img src="http://2.bp.blogspot.com/_clRkdFNwbPo/SdhsEAGHytI/AAAAAAAAAFM/RlJNraeGTjM/s320/orb02.jpg" width="72" height="72" alt="An orb in my lounge!" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What are these orbs, are they really supernatural?  Some people would say it is from the flash reflection within the TV.  I'm not so sure because of the angles, but I will leave the conclusion upto you!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4530474081110248662-926883171178940182?l=www.mshed.co.uk' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.mshed.co.uk/feeds/926883171178940182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.mshed.co.uk/2009/04/orbs-phenomenon.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/926883171178940182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4530474081110248662/posts/default/926883171178940182'/><link rel='alternate' type='text/html' href='http://www.mshed.co.uk/2009/04/orbs-phenomenon.html' title='An Orb In My Lounge!'/><author><name>Pete Shipstone</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13959464823780675819'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_clRkdFNwbPo/SdhsEAGHytI/AAAAAAAAAFM/RlJNraeGTjM/s72-c/orb02.jpg' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>