Friday, November 19, 2010

How to Escape Special Characters in XML from C#

I have written a code which escape special characters in XML while posting an XML Request. Here is the sample code sample.

private string EscapeXMLillegalCharacters (string strValue)
{
    return strValue.Replace("&", "&amp;").Replace("'", "&apos;").Replace("\"", "&quot;").Replace("<", "&lt;").Replace(">", "&gt;");
}

Hope this is useful. Happy coding Smile

What are the special characters in XML?

If you use XML with no DTD, then these five character entities are assumed to be pre declared, and you can use them without declaring them:

&lt;
The less-than character (<) starts element markup (the first character of a start-tag or an end-tag).

&amp;
The ampersand character (&) starts entity markup (the first character of a character entity reference).

&gt;
The greater-than character (>) ends a start-tag or an end-tag.

&quot;
The double-quote character (") can be symbolized with this character entity reference when you need to embed a double-quote inside a string which is already double-quoted.

&apos;
The apostrophe or single-quote character (') can be symbolized with this character entity reference when you need to embed a single-quote or apostrophe inside a string which is already single-quoted.

If you are using a DTD then you must declare all the character entities you need to use (if any), including any of the five above that you plan on using (they cease to be pre declared if you use a DTD). If you are using a Schema, you must use the numeric form for all except the five above because Schemas have no way to make character entity declarations.

Tuesday, November 16, 2010

Help full Tools and Converters

Here are some useful tools and converters which are helpful for conversion and compression

.NET Code converters

You can translate any C# code to VB.NET and VB.NET to C#.

http://converter.telerik.com/

http://www.aspalliance.com/aldotnet/examples/translate.aspx

http://www.developerfusion.com/utilities/convertcsharptovb.aspx

I have used first URL from telerik. Its works just great

Compress your CSS

http://www.developerfusion.com/tools/compresscss/

Compress and obfuscate javascript

http://www.developerfusion.com/tools/compressjavascript/

Clear Browser History Through Javascript

If you need to clear the Browser History, after arriving on a particular page (e.g. arriving to Login page after Logout).

Here is the code to do this. If you put this code in Login page, it wont take it to be back page. You need to put this from where you do not want to move back. Here is the code snippet.

<script type="text/javascript">
        window.onload = function () { Clear(); }
        function Clear() {            
            var Backlen = history.length;
            if (Backlen > 0) history.go(-Backlen);
        }
</script>

if you do not want the user to move to the back page, you can do as below. This script needs to be repeated at where you don’t want to do this.

<script type="text/javascript">
       if(window.history.forward(1) != null)
           window.history.forward(1);
</script>

Hope this helps.

Monday, November 15, 2010

Utility : Dell Dock

I have been waiting for some thing like this from Microsoft for so long. I have seen this in Mac and Linux system. But Star dock has build it for Dell. The Dell Dock is a task-based organizer for Dell Laptops or Desktops. It is helpful to the users to sort their software applications into friendly categories, which can be accessed easily from a dock. So that the user can leave the desktop free of clutter. Dell Customers don't have to locate and open a program by application name by rather can locate it by task, like "email & chat", "security", "view photos", "play music", etc..

Here is the screen shot how it look like once you install it

image

Download.

Hope this is useful. I Love it Smile