Nick Allen – Tungle139

They are indeed different, but they are of the same kind, as there is no duality in Truth

Creating a QueryString utility Class

Building up query strings is quite a common task in web development but there is currently no utility class in .Net that neatly facilitates this. So I thought I’d have a go at creating one that nicely encapsulates the build process and makes use of Generic Collections. And here is what I came up with!

public class QueryString
{
    private Dictionary _Params = new Dictionary();

    public overide ToString()
    {
        List returnParams = new List();

        foreach (KeyValuePair param in _Params)
        {
            returnParams.Add(String.Format("{0}={1}", param.Key, param.Value));
        }

        return "?" + String.Join("&", returnParams.ToArray());
    }

    public void Add(string key, string value)
    {
        _Params.Add(key, HttpUtility.UrlEncode(value));
    }
}

This can be used like so

QueryString query = new QueryString();

query.Add("param1", "value1");
query.Add("param2", "value2");

return query.ToString();

Filed under: Code

Switching from XHTML to HTML

There has been a noticeable shift of developers deciding to abandon the XHTML doctype due to the lack of movement in the delivery of XHTML 2.0 and the continued efforts of browser vendors to implement HTML 5 as the new standard and way forward. This to me makes sense so I have also decided to down tools with XHTML and go back to a HTML 4 strict doctype for now until I make the move up to HTML5.

This may not be the easy ride I was hoping for and I get the feeling that years of XHTML tag mentality may make the switch a little trickier than I thought. Take the following example…

I published my first piece of work and ran it through the W3C Validator and to my surprise (as it is quite simple markup) it failed on 1 error but in several places. The reason at first was not obvious but after reading up on empty elements it turns out that in HTML I should not be using a forward slash in front of the closing greater than character in self closing tags

The browser will see

<link rel=”stylesheet” type=”text/css” href=”style.css”/>

as

<link rel=”stylesheet” type=”text/css” href=”style.css”>>

A simple mistake to make and a simple mistake to rectify but I get the impression that this is the first in a long line of XHTML conventions I will need to, not shake off as I will still have XHTML projects to work on but retrain the mind on when working with HTML

Filed under: Web Development, , ,

Pages

Del.icio.us Bookmarks

 

May 2009
M T W T F S S
« Feb    
 123
45678910
11121314151617
18192021222324
25262728293031

Where Am I?

Flickr Photostream

Times Square

Statue of Liberty

Madison Square Garden

The Legendary Fat Beats NYC

The Legendary Fat Beats NYC

More Photos
Follow

Get every new post delivered to your Inbox.