Html, Url & Xml encoding page and script

Lately I've been reading David Flanagan's JavaScript: The Definitive Guide on my commute.  It is a must have if you are a web developer!

A couple of weeks ago I started some encoding scripts about the same time I was reading the chapter on how to create namespaces is JavaScript, but didn't have the time to finish the work until today.

I have updated my Encoding Page to now have decoding and to use a new JH.Utilities javascript class (download here).

The functions in this class are:

JH.Utilities.HtmlEncode(textToEncode) - replaces the common English entities with their html version (ie. & = &)

JH.Utilities.HtmlDecode(textToDecode) - replaces the common html entities with their English version (ie. & = &)

JH.Utilities.HtmlEncode2(textToEncode) - replaces the characters with their html escaped version (ie. & = &)

JH.Utilities.HtmlDecode2(textToDecode) - replaces the escaped characters with their English characters (ie. & = &)

JH.Utilities.UrlEncode(textToEncode) - replaces the characters with their escaped Url version (ie. a space = %20)

JH.Utilities.UrlDecode(textToDecode) - replaces the escaped Url characters with their English version (ie. %20 = a space)

JH.Utilities.XmlEncode(textToEncode) - replaces the common English entities with their Xml version (ie. & = &)

JH.Utilities.XmlDecode(textToDecode) - replaces the escaped characters with their common English version (ie. & = &)

NOTE: I have only briefly tested these scripts, so if you are going to take them and use them - beware there are probably bugs in them.

If you just need to Url encode a string or decode an Url, you should use javascript's functions such as encodeURI/decodeURI, encodeURIComponent/decodeURIComponent or the older escape/unescape.  The only reason I implemented my own was for the sure joy of it :)

posted on Saturday, September 30, 2006 9:02 PM

Feedback

# Link Listing - October 2, 2006

The Dangers of Cross-Domain Ajax with Flash [Via: Chris Cornutt ] In-Browser Wireframe Prototyping with...
10/2/2006 10:35 PM | Christopher Steen

# re: Html, Url & Xml encoding page and script

This looks pretty handy. What is the licensing for this code?
5/17/2007 4:50 PM | sartre

# re: Html, Url & Xml encoding page and script

I second that. Very handy, indeed.

What's the licensing?
6/25/2007 7:22 PM | Daniel Cormier

# re: Html, Url & Xml encoding page and script

No licensing, just take the code and do no evil :)
9/25/2007 12:07 PM | Jason Haley

Post Comment

Title  
Name  
Url
Comment   
Please enter the following code into the box below to stop spammers

  
Enter Code Here *