<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fremus.co.za</title>
	<atom:link href="http://www.fremus.co.za/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fremus.co.za/blog</link>
	<description>Demistifying Life and Web Development</description>
	<lastBuildDate>Mon, 01 Feb 2010 10:31:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A case for ASP.NET MVC</title>
		<link>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/</link>
		<comments>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 10:31:43 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=565</guid>
		<description><![CDATA[What is the case for ASP.NET MVC? Lets forget the architecture for a minute and just focus on what it offers me as the developer, or rather what features do the other ASP.NET technologies offer that I do not like using. For starters web forms are &#8216;heavy&#8217; and not as lightweight as ashx files. ASHX [...]]]></description>
			<content:encoded><![CDATA[<p>What is the case for ASP.NET MVC? Lets forget the architecture for a minute and just focus on what it offers me as the developer, or rather what features do the other ASP.NET technologies offer that I do not like using. For starters web forms are &#8216;heavy&#8217; and not as lightweight as ashx files. ASHX files are lighter because they do not have all the overheads a webform has, but they lack HTML support. The HTML support in webforms sucks because it does not render clean HTML, the tag id&#8217;s for instance, and viewstate are examples of &#8216;unclean&#8217; html. For HTML support in a ashx file you will need to write some code that reads HTML and renders it, plus you will have to do some string manipulation somewhere to place content in the HTML. This seems a bit cumbersome to me. Why cant I have my HTML generated without having to do something like that, but also without worrying about clean HTML. ASP.NET MVC renders clean HTML. ASP.NET MVC Controllers are also available through XmlHttpRequests, making it easy to implement AJAX functionality.</p>
<p>Two reasons to use ASP.NET MVC:</p>
<ul>
<li>Clean HTML</li>
<li>Controllers can be called from JavaScript</li>
</ul>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2010%2F02%2Fa-case-for-asp-net-mvc%2F&amp;linkname=A%20case%20for%20ASP.NET%20MVC" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2010_2F02_2Fa-case-for-asp-net-mvc_2F_amp_linkname=A_20case_20for_20ASP.NET_20MVC&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can you get to generic without going non-generic?</title>
		<link>http://www.fremus.co.za/blog/2010/01/can-you-get-to-generic-without-going-non-generic/</link>
		<comments>http://www.fremus.co.za/blog/2010/01/can-you-get-to-generic-without-going-non-generic/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:04:29 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[General Thoughts]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=563</guid>
		<description><![CDATA[This is a seemingly trivial question but one that I have been thinking about for a while. Is it possible to come up with a completely generic solution, without having first gone the non-generic route? Let me ask another question. Will the initial stages in any project deliver enough &#8216;generic-ness&#8216;? The reason I ask and [...]]]></description>
			<content:encoded><![CDATA[<p>This is a seemingly trivial question but one that I have been thinking about for a while. Is it possible to come up with a completely generic solution, without having first gone the non-generic route? Let me ask another question. Will the initial stages in any project deliver enough &#8216;<em>generic-ness</em>&#8216;? The reason I ask and say this is because in my experience a generic system cannot be achieved if you haven&#8217;t worked through its non-generic counterpart. Why is it then that we as developers always want to improve and rework our code? Is it because we have had time to think about the solution, creating a better understanding of what problem the solution is trying to solve, and now that a better understanding exists you can look at your code easily and go hmmm, lets rather try this approach and see what happens. I often find myself going through my code trying to explain each line to myself, because in theory you should understand your own code, right? On these odd occasions that I go through my code a few times I do get to see ways of better structuring my code, but it usually couples itself with a better understanding of the business paradigm. </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2010%2F01%2Fcan-you-get-to-generic-without-going-non-generic%2F&amp;linkname=Can%20you%20get%20to%20generic%20without%20going%20non-generic%3F" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2010_2F01_2Fcan-you-get-to-generic-without-going-non-generic_2F_amp_linkname=Can_20you_20get_20to_20generic_20without_20going_20non-generic_3F&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2010/01/can-you-get-to-generic-without-going-non-generic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting code with HtmlAgilityPack</title>
		<link>http://www.fremus.co.za/blog/2009/12/interesting-code-with-htmlagilitypack/</link>
		<comments>http://www.fremus.co.za/blog/2009/12/interesting-code-with-htmlagilitypack/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 12:04:09 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML Agility]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=548</guid>
		<description><![CDATA[Yesterday I was busy with HTML to PDF conversion and for this I used the HTML Agility Pack. Everything worked great, except it seemed IE and FF/Chrome render different HTML. So today I took some fairly straightforward HTML and pushed it through HTMLAgility:






	
	








			New Website Under Construction
		

		


	




And if I use this code to loop through the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was busy with HTML to PDF conversion and for this I used the HTML Agility Pack. Everything worked great, except it seemed IE and FF/Chrome render different HTML. So today I took some fairly straightforward HTML and pushed it through HTMLAgility:</p>
<pre name="code" class="html">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

	<meta name="copyright" content="Copyright (c) 2009 Fredrik Erasmus">
	<meta name="author" content="Fredrik Erasmus">
<link rel="stylesheet" href="css/default.css" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="left_header"></div>
</div>
<div id="container">
<div id="main">
			New Website Under Construction
		</div>
<div id="sidebar">
		</div>
</div>
<div id="footer">
	</div>

</body>
</html>
</pre>
<p>And if I use this code to loop through the childnodes:</p>
<pre name="code" class="csharp">
            HtmlDocument doc = new HtmlDocument();
            string s;
            StringBuilder builder = new StringBuilder();
            using (StreamReader reader = new StreamReader(@"C:\Documents and Settings\user\Desktop\fremus.net\index.htm"))
            {
                while ((s = reader.ReadLine()) != null)
                {
                    builder.AppendLine(s);
                }
            }
            doc.LoadHtml(builder.ToString());
            Console.WriteLine(doc.DocumentNode.ChildNodes.Count);
            foreach (HtmlNode node in doc.DocumentNode.ChildNodes)
            {
                Console.WriteLine(node.Name);
                foreach (HtmlNode childNode in node.ChildNodes)
                {
                    Console.WriteLine("\t\t" + childNode.Name);
                    foreach (HtmlNode grandChildNode in childNode.ChildNodes)
                    {
                        Console.WriteLine("\t\t\t" + grandChildNode.Name);
                    }
                }
            }
</pre>
<p>I get the following result in my command line window:<br />
<a href="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/cmdline.JPG"><img src="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/cmdline.JPG" alt="cmdline" title="cmdline" width="668" height="335" class="alignleft size-full wp-image-549" /></a></p>
<p>As you can see from the output the html node has a text node. The head node has a text node, and it has 9 childnodes including 5 #text nodes. The body node has a text node as well, and it has 7 childnodes, four being #text and the other three being div. So what is this #text node? If you read <a href="http://www.w3schools.com/htmldom/dom_nodes.asp" onclick="urchinTracker('/outgoing/www.w3schools.com/htmldom/dom_nodes.asp?referer=');">this article</a> on the W3C site you will see that it states:</p>
<blockquote><p>A common error in DOM processing is to expect an element node to contain text.</p>
<p>However, the text of an element node is stored in a text node.
</p></blockquote>
<p>On the same page it then gives an example using a title tag. If you do a Google on &#8220;<em>html #text node</em>&#8220;, you will see that the second result points to <a href="http://www.quirksmode.org/dom/intro.html" onclick="urchinTracker('/outgoing/www.quirksmode.org/dom/intro.html?referer=');">an article</a> and if you read the bit on the nodes it seems that each #text node is a child. The #text nodes that appear in the body node seem to point to the text spaces after each div or each element inside the body node. If I change my code slightly:</p>
<pre name="code" class="csharp">
                    Console.WriteLine("\t\t" + childNode.Name);
                    foreach (HtmlNode grandChildNode in childNode.ChildNodes)
                    {
                        Console.WriteLine("\t\t\t" + grandChildNode.Name);
                        Console.WriteLine("\t\t\t\t" + grandChildNode.HasChildNodes);
                    }
</pre>
<p>It tells me that the divs have child elements, but the #text nodes do not. Thus it seems for each &#8216;empty space&#8217; inside a node there exists a #text node. If I amend the HTML from earlier like this:</p>
<pre name="code" class="html">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

	<meta name="copyright" content="Copyright (c) 2009 Fredrik Erasmus">
	<meta name="author" content="Fredrik Erasmus">
<link rel="stylesheet" href="css/default.css" type="text/css" media="screen" />
</head>
<body>
<div id="footer">

Test
</div>

</body>
</html>
</pre>
<p>Then the footer div will have two text nodes, and the paragraph node will have a textnode. My issues yesterday had to do with the way IE rendered the HTML and that when I used HTMLAgility to parse it, the node counts weren&#8217;t the same. From the sample HTML I have given so far that difference is negligble, but I found that if I went to a site like <a href="http://www.w3schools.com/htmldom/dom_nodes_info.asp" onclick="urchinTracker('/outgoing/www.w3schools.com/htmldom/dom_nodes_info.asp?referer=');">this one</a> and I saved the HTML from IE and Chrome into separate HTML files and I ran my code with that HTML, I got different node counts. Here are two screenshots that illustrate this:<br />
<a href="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/chrome.JPG"><img src="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/chrome.JPG" alt="chrome" title="chrome" width="670" height="338" class="alignleft size-full wp-image-559" /></a><a href="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/ie.JPG"><img src="http://www.fremus.co.za/blog/wp-content/uploads/2009/12/ie.JPG" alt="ie" title="ie" width="666" height="337" class="alignleft size-full wp-image-560" /></a></p>
<p>The first screen is the html from the page saved from chrome and the second one is from ie. Notice the extra text nodes. </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F12%2Finteresting-code-with-htmlagilitypack%2F&amp;linkname=Interesting%20code%20with%20HtmlAgilityPack" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F12_2Finteresting-code-with-htmlagilitypack_2F_amp_linkname=Interesting_20code_20with_20HtmlAgilityPack&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/12/interesting-code-with-htmlagilitypack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF &#8211; Getting the foundations right</title>
		<link>http://www.fremus.co.za/blog/2009/12/wcf-getting-the-foundations-right/</link>
		<comments>http://www.fremus.co.za/blog/2009/12/wcf-getting-the-foundations-right/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 20:31:46 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=546</guid>
		<description><![CDATA[Ok so admittedly I have been using ASMX services for too long now and the time has come to kick it to the curb and adopt WCF. And the issue I have been having of late was that I was skimming through code just to get stuff done, without spending the time understanding some of [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so admittedly I have been using ASMX services for too long now and the time has come to kick it to the curb and adopt WCF. And the issue I have been having of late was that I was skimming through code just to get stuff done, without spending the time understanding some of the details. </p>
<p>Why would I want to adopt WCF? Well there are the list of reasons found in articles on MSDN, one whitepaper can be <a href="http://msdn.microsoft.com/en-us/library/dd943056.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/dd943056.aspx?referer=');">found here</a>, and of particular interest is the combination of technologies and the general idea that interoperability is the main goal. But these things are just a way of promoting the technology, and its not until you understand what it can do that you realise what it is you are dealing with. And to help you get to that point you need to work through an example, and I found that after I worked through <a href="http://msdn.microsoft.com/en-us/library/ms734712.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/ms734712.aspx?referer=');">the &#8220;Getting Started Tutorial&#8221; example</a>, a light went on and I was like, &#8220;ok I get it&#8221;. Essentially a WCF service is made up of two key elements (there is a third as well) but in terms of C# code there are two key elements:<br />
*An interface marked as a Service Contract using the ServiceContract attribute and with the methods marked as OperationContracts using an attribute with the same name<br />
*A class that implements the methods in the interface</p>
<p>The third part of a WCF service is the configuration settings which can be found in a web.config/app.config&#8217;s system.servicemodel tag. Within the servicemodel section you define service behaviours as well as endpoints. One of the keys to understanding WCF is knowing that a service is defined by its endpoint, see it as a consumer. WCF can be consumed by client web apps, Silverlight apps and desktop apps. The endpoints themselves have configuration settings as well specifically relating to message sizes. </p>
<p>From the tutorial I was able to see that you can run a WCF service in a browser, without having IIS running. Thats something I need to think about but it does pose a few interesting questions. After I did the tutorial I wanted to do a simple REST service, and that took a few minutes but eventually got that sorted. StackOverflow was quite helpful and so was several articles on MSDN, with <a href="http://msdn.microsoft.com/en-us/library/bb885100.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/bb885100.aspx?referer=');">this one</a> being the most helpful.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F12%2Fwcf-getting-the-foundations-right%2F&amp;linkname=WCF%20%26%238211%3B%20Getting%20the%20foundations%20right" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F12_2Fwcf-getting-the-foundations-right_2F_amp_linkname=WCF_20_26_238211_3B_20Getting_20the_20foundations_20right&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/12/wcf-getting-the-foundations-right/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using System.Uri&#8217;s Segments property and List().ForEach</title>
		<link>http://www.fremus.co.za/blog/2009/11/using-system-uris-segments-property-and-list-foreach/</link>
		<comments>http://www.fremus.co.za/blog/2009/11/using-system-uris-segments-property-and-list-foreach/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 08:20:59 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=542</guid>
		<description><![CDATA[You know the feeling when you see someone use a property and you go, nice, I never knew that. Well last night that happened to me after reading Scott Hanselman&#8217;s article on Windows Powershell. In the article he created a script that automatically downloaded his podcasts. To do this he use the System.Uri class which [...]]]></description>
			<content:encoded><![CDATA[<p>You know the feeling when you see someone use a property and you go, nice, I never knew that. Well last night that happened to me after reading Scott Hanselman&#8217;s article on Windows Powershell. In the article he created a script that automatically downloaded his podcasts. To do this he use the System.Uri class which has a property called Segments. Segments returns a string array which consists of elements in a Uri separated by a forward slash &#8216;/&#8217;. So lets say you have this url:</p>
<p>http://developer.yahoo.com/yap/guide/caja-support.html</p>
<p>You could then use System.Uri to get all the bits in the Uri like this:</p>
<pre name="code" class="csharp">
            Uri url = new Uri("http://developer.yahoo.com/yap/guide/caja-support.html");

            string[] arrUri = url.Segments;
            var item = from u in arrUri
                       select u;

            foreach (string s in item)
            {
                Console.WriteLine(s);
            }
</pre>
<p>Something else I started doing or using yesterday is the ToList().ForEach delegate method. I noticed it in the LinqToTwitter api:</p>
<pre name="code" class="csharp">

            var twitterTrends = from trends in tCtx.Trends
                                select trends;

            twitterTrends.ToList().ForEach(t =>
                Console.WriteLine(t.Query));
</pre>
<p>The ForEach works on a list as well, so if you take the same code I wrote earlier using a foreach loop for the Uri segments you can rewrite that as:</p>
<pre name="code" class="csharp">

item.ToList().ForEach(s => Console.WriteLine(s));
</pre>
<p>The variable s is an anonymous type so it infers from the type what type it is. That is shorter code, not sure if its more efficient, but it sure looks nicer.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F11%2Fusing-system-uris-segments-property-and-list-foreach%2F&amp;linkname=Using%20System.Uri%26%238217%3Bs%20Segments%20property%20and%20List%28%29.ForEach" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F11_2Fusing-system-uris-segments-property-and-list-foreach_2F_amp_linkname=Using_20System.Uri_26_238217_3Bs_20Segments_20property_20and_20List_28_29.ForEach&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/11/using-system-uris-segments-property-and-list-foreach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inkscape supports XAML</title>
		<link>http://www.fremus.co.za/blog/2009/11/inkscape-supports-xaml/</link>
		<comments>http://www.fremus.co.za/blog/2009/11/inkscape-supports-xaml/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 07:06:16 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Inkscape]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=540</guid>
		<description><![CDATA[I have been using Inkscape now for a while and I was surprised to see XAML as an export format. This means that I can design UI elements in Inkscape and re-use them in Visual Studio 2008 for WPF/Silverlight applications. This means that I do not have to buy Expression Design, which is a bargain.
]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://www.inkscape.org/" onclick="urchinTracker('/outgoing/www.inkscape.org/?referer=');">Inkscape</a> now for a while and I was surprised to see XAML as an export format. This means that I can design UI elements in <a href="http://www.inkscape.org/" onclick="urchinTracker('/outgoing/www.inkscape.org/?referer=');">Inkscape</a> and re-use them in Visual Studio 2008 for WPF/Silverlight applications. This means that I do not have to buy Expression Design, which is a bargain.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F11%2Finkscape-supports-xaml%2F&amp;linkname=Inkscape%20supports%20XAML" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F11_2Finkscape-supports-xaml_2F_amp_linkname=Inkscape_20supports_20XAML&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/11/inkscape-supports-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Will email truly die?</title>
		<link>http://www.fremus.co.za/blog/2009/11/will-email-truly-die/</link>
		<comments>http://www.fremus.co.za/blog/2009/11/will-email-truly-die/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 17:39:54 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=538</guid>
		<description><![CDATA[I got a Google Wave invite earlier this week and I must admit I have not logged in again since and honestly I have not felt compelled to, but that may just be me. Maybe it is just me, maybe I am not as forward and revolutionary thinking as the people over at Google. To [...]]]></description>
			<content:encoded><![CDATA[<p>I got a Google Wave invite earlier this week and I must admit I have not logged in again since and honestly I have not felt compelled to, but that may just be me. Maybe it is just me, maybe I am not as forward and revolutionary thinking as the people over at Google. To be completely honest though I do find it quite scary when Google start tapping into our everyday lives, even if they profess to be squeaky clean and all. Just because they seem to be a lesser evil doesnt mean they are less evil. Back to the topic at hand though, will email truly die? In South Africa I do not really think it would, maybe in years to come. What would replace it though? Mobile messaging? I mean the South African environment is filled with Mxiteers and who is to say that in 10 or so years from now Mxit would replace email as contemporary communication tool. But as things stand at the moment you cannot dispose of email really. I mean some people live from Outlook, their whole job and existence is documented there, what about them? Email remains a very useful tool to communicate and to keep a track of communication, although I do believe this is where Google Groups is cool. As I said at the start maybe I don&#8217;t get Google Wave yet. Until then I guess email will remain.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F11%2Fwill-email-truly-die%2F&amp;linkname=Will%20email%20truly%20die%3F" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F11_2Fwill-email-truly-die_2F_amp_linkname=Will_20email_20truly_20die_3F&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/11/will-email-truly-die/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting POST values with an ASHX file</title>
		<link>http://www.fremus.co.za/blog/2009/11/getting-post-values-with-an-ashx-file/</link>
		<comments>http://www.fremus.co.za/blog/2009/11/getting-post-values-with-an-ashx-file/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 12:56:32 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Technologies]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=536</guid>
		<description><![CDATA[Today I had this scenario where I wanted to post items from multiple HTML input elements to a generic handler (.ashx) file without using the action attribute of the form. Specifying the action meant that that you are navigated away from the page where the action is happening, which means re-creating UI logic. How did [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had this scenario where I wanted to post items from multiple HTML input elements to a generic handler (.ashx) file without using the action attribute of the form. Specifying the action meant that that you are navigated away from the page where the action is happening, which means re-creating UI logic. How did I achieve this? By using an XMLHttpRequest and using a POST method. GET places everything inside a querystring, which is ok, but I just wondered what would happen if the content was too long for the querystring. I guess the same can be said for POST, but it just seems POST uses a different way to transfer the data. So lets say you had this JavaScript:</p>
<pre name="code" class="javascript">
    getXMLHTTPPostObject: function(url, elementName, parameters) {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP!");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                document.getElementById(elementName).innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST", url, true);
        xmlhttp.send(parameters);
    }
</pre>
<p>I use this function to create an XMLHttpRequest object by passing it:</p>
<ul>
<li>the URL for the AJAX call</li>
<li>an elementName to put the result of request in</li>
<li>A parameter list</li>
</ul>
<p>I then have a function like this:</p>
<pre name="code" class="javascript">
    addPost: function() {
        objXMLHTTP.getXMLHTTPPostObject("url to handler", "categoryTemp", "postTitle=" + document.getElementById("txtPostTitle").value + "&#038;blogpost=" + document.getElementById("txtBlogPost").value);
    }
</pre>
<p>The function gets the values of two HTML input elements and passes it as parameters. The parameters are then used in the POST HTTPMethod. My next challenge was to get the data in the generic handler (.ashx) so that I can process it. I also wanted to return the data from the ASHX file to see that its processed successfully. So in my handler I created this code:</p>
<pre name="code" class="csharp">
        context.Response.ContentType = "text/plain";
        System.IO.Stream body = context.Request.InputStream;
        System.Text.Encoding encoding = context.Request.ContentEncoding;
        System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
        //if (context.Request.ContentType != null)
        //{
        //    context.Response.Write("Client data content type " + context.Request.ContentType);
        //}
        string s = reader.ReadToEnd();
        string[] content = s.Split('&#038;');
        for (int i = 0; i < content.Length; i++)
        {
            string[] fields = content[i].Split('=');
            context.Response.Write("
<div><strong>" + fields[0] + "</strong></div>

");
            context.Response.Write("
<div>" + fields[1] + "</div>

");
        }
        //context.Response.Write(s);
        body.Close();
        reader.Close();
</pre>
<p>I first create a class of type Stream that is instantiated through the Response.InputStream property, after which I set the content encoding for the response object. I then create a StreamReader instance and call its ReadToEnd method. After this I do some string manipulation and return the text back to the XMLHttpRequest object, which then writes the content to an HTML Element.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F11%2Fgetting-post-values-with-an-ashx-file%2F&amp;linkname=Getting%20POST%20values%20with%20an%20ASHX%20file" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F11_2Fgetting-post-values-with-an-ashx-file_2F_amp_linkname=Getting_20POST_20values_20with_20an_20ASHX_20file&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/11/getting-post-values-with-an-ashx-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a single XAttribute or XElement</title>
		<link>http://www.fremus.co.za/blog/2009/11/getting-a-single-xattribute-or-xelement/</link>
		<comments>http://www.fremus.co.za/blog/2009/11/getting-a-single-xattribute-or-xelement/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 13:15:43 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ to XML]]></category>
		<category><![CDATA[XAttribute]]></category>
		<category><![CDATA[XElement]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=534</guid>
		<description><![CDATA[I have come across two ways querying XElements or XAttributes:

Make an object IEnumerable and loop through the results
Use the Single() method to return a single object only

Typically you may have a situation where you write some Linq-to-XML like this:

IEnumerable attrib = from att in elemInner.Attributes()
           [...]]]></description>
			<content:encoded><![CDATA[<p>I have come across two ways querying XElements or XAttributes:</p>
<ul>
<li>Make an object IEnumerable and loop through the results</li>
<li>Use the <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.single.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/system.linq.enumerable.single.aspx?referer=');">Single()</a> method to return a single object only</li>
</ul>
<p>Typically you may have a situation where you write some Linq-to-XML like this:</p>
<pre name="code" class="csharp">
IEnumerable<XAttribute> attrib = from att in elemInner.Attributes()
                                             where (string)att.Name.ToString() == "sectionName"
                                             select att;
</pre>
<p>To loop through the results you have to use a foreach loop like this:</p>
<pre name="code" class="csharp">

foreach (XAttribute innerAttrib in attrib)
{
     builder.AppendLine("
<h3>" + innerAttrib.Value +"</h3>

");
}
</pre>
<p>If however you just wanted a single attribute result, you could write the same code like this:</p>
<pre name="code" class="csharp">

 XAttribute attribDisplayStyle = (from att in elemInner.Attributes()
                                            where (string)att.Name.ToString() == "sectionName"
                                            select att).Single();
</pre>
<p>Then you only have a single XAttribute instance and you dont need a foreach loop:</p>
<pre name="code" class="csharp">

attribDisplayStyle.Value;
</pre>
<p>You would apply the same logic to XElement as well.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F11%2Fgetting-a-single-xattribute-or-xelement%2F&amp;linkname=Getting%20a%20single%20XAttribute%20or%20XElement" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F11_2Fgetting-a-single-xattribute-or-xelement_2F_amp_linkname=Getting_20a_20single_20XAttribute_20or_20XElement&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/11/getting-a-single-xattribute-or-xelement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript alphabetical sorting (A is less than a)</title>
		<link>http://www.fremus.co.za/blog/2009/10/javascript-alphabetical-sorting-a-a/</link>
		<comments>http://www.fremus.co.za/blog/2009/10/javascript-alphabetical-sorting-a-a/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 14:24:53 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Technologies]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=532</guid>
		<description><![CDATA[So A < a, which means if you use the sort() function and your array contains elements starting with upper and lowercase then the uppercase will appear first, i.e.:
Art, ASP.NET, LawDeed, LINQ will appear as:
ASP.NET
Art
LawDeed
LINQ
To get this working correctly you need the following function:

    charOrdA: function(a, b) {
     [...]]]></description>
			<content:encoded><![CDATA[<p>So A < a, which means if you use the sort() function and your array contains elements starting with upper and lowercase then the uppercase will appear first, i.e.:</p>
<p>Art, ASP.NET, LawDeed, LINQ will appear as:<br />
ASP.NET<br />
Art<br />
LawDeed<br />
LINQ</p>
<p>To get this working correctly you need the following function:</p>
<pre name="code" class="javascript">
    charOrdA: function(a, b) {
        a = a.toLowerCase(); b = b.toLowerCase();
        if (a > b) return 1;
        if (a < b) return -1;
        return 0;
    }
</pre>
<p>This function will make sure your alphabetical sortorder is correct so that the list appears like this:<br />
Art<br />
ASP.NET<br />
LawDeed<br />
LINQ</p>
<p>You have to pass the function name to the sort function like this:</p>
<pre name="code" class="javascript">

arrCategories.sort(charOrdA);
</pre>
<p>Note that there are no parenthesis.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.fremus.co.za%2Fblog%2F2009%2F10%2Fjavascript-alphabetical-sorting-a-a%2F&amp;linkname=JavaScript%20alphabetical%20sorting%20%28A%20is%20less%20than%20a%29" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Fwww.fremus.co.za_2Fblog_2F2009_2F10_2Fjavascript-alphabetical-sorting-a-a_2F_amp_linkname=JavaScript_20alphabetical_20sorting_20_28A_20is_20less_20than_20a_29&amp;referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/10/javascript-alphabetical-sorting-a-a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
