Suresh Behera

The Microsoft .Net Junkies

News

Blogroll

Reading

February 2006 - Posts

Single and Double Quote for XML document

On my last article we are talking about replacing special character for XML document which was working great but our testing team able to break it again. The single and double quote character are different from NOTEPAD to Microsoft Word .Here is how it looks and it's decimal/Hex value

 

SINGLE QUOTE

NOTEPAD

Microsoft WORD

OPENING

CLOSING

OPENING

CLOSING

'

DEC  '

HEX  '

'

DEC  '

HEX  '

DEC    ‘

HEX    ‘

DEC  ’

HEX  ’

 

DOUBLE QUOTE

NOTEPAD

Microsoft WORD

OPENING

CLOSING

OPENING

CLOSING

"

DEC "

HEX "

"

DEC "

HEX "

DEC “

HEX “

DEC ”

HEX ”

Again, How do you replace in C# code ?
The best way it to write a Regular Expression but for quick solution use this code

newString = newString.Replace("'","'");

//" Double Quote Word oepning
newString = newString.Replace(""","“");

//" Double Quote Word Closing
newString = newString.Replace(""","”");

//‘ Single Quote Word oepning
newString = newString.Replace("‘","‘");

//’ Single Quote Word Closing
newString = newString.Replace("’","’");

How do you write or produce C# code for  Microsoft Word Single Quote  like this (not like ')
?
Well, To be frank I did not found any keyboard letter to write this character ;) Use the traditional method like copy the character from Microsoft Word and paste in VS .Net C# editor. Just like above and this works for other characters too.

For example :
The string conversation might look like this

Before :
This’s testing for “Double quote from MS word” and ‘single quote from MS Word’  'NOTEPAD' \"NOTEPAD\"

After  :
This’s testing for “Double quote from MS word” and ‘single quote from MS Word’  'NOTEPAD' \"NOTEPAD\"

Here is the link to convert character

Hope you enjoy this coding..Keep tune lots more fun part is coming up :)

Suresh Behera

 

 

 

 

Posted: Feb 28 2006, 05:04 PM by Suresh Behera | with 1 comment(s)
Filed under: ,
Java (J2SE 5.0) Vs VB.NET Vs C# Comparison

Syntactical differences between Java and C#.

Syntactical differences between VB.NETand C#.

More reading
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html

Suresh Behera

A-Z download from Microsoft

Here is a list of all downloads in the Microsoft Download Center, grouped by product or technology.

A

 

B

 

C

D

E

F

G

H

I

J

L

M

N

O

P

R

S

T

V

W

X

Z

Others

More reading at

http://www.microsoft.com/downloads/Products.aspx?displaylang=en

Suresh Behera

Characters filteration or validation for XML document.

I was having hard time to filer form input from a asp.net page. This page accept text as input and send to database in terms of xml formats.
All are ok when the text doest not include any of the following character. It gone for toss when you use these charactes

 

Character Name

Entity Reference

Character Reference

Numeric Reference

Ampersand

&

&

&

Left angle bracket

<

< 

&#38;#60;

Right angle bracket

&gt;

> 

&#62;

Straight quotation mark

&quot;

"

&#39;

Apostrophe

&apos;

'

&#34;

Microsoft has one suport article but it does not give sufficent help for this problem.
How to locate and replace special characters in an XML file with Visual C# .NET

I tried different way to workaround this and I could be following any of these
1 - You simple filter the text using c# or VB.Net Replace method
Like

// >

newString = newString.Replace(">","&gt;");

//  <

newString = newString.Replace("<","&lt;");

//&

newString = newString.Replace("&","&amp;");

//Double Quote " –This does not work here…

// newString = newString.Replace(ControlChars.Quote,"&quot;");

 Here C# does not have any class called ControlChars

// newString = newString.Replace(CHR(32),"&quot;");

Replace method accept either both character or both string not one character and another string. So this also does not work.

 

//Single Quote '
newText = newText.Replace("'","&apos;");

 2. You can use Regular expression to filter all you special character.It might be something like this @"a1/}{]yryr23dsdhds%$#yytr^&uut887611oiuif():><?jfhgg";

3. You can write stored procedure to replace all these special characters.

Regular expression was good choice but it was killing lots of time to make the expression. I am not so good on regular expression or might not be wanted to waste much time for this simple problem. If somebody could write the expression it would be great and helpful for others

How To Locate and Replace Special Characters in an XML Document with Visual Basic

 

Some extra reading
XML Syntax and Parsing Concepts
Manipulating Strings in C#

 

Happy Coding

 

Suresh Behera

Posted: Feb 24 2006, 04:24 PM by Suresh Behera | with 7 comment(s)
Filed under: ,
Security and Microsoft .Net Technologies

Security Question List: Managed Code (.NET Framework 2.0)
How to Use This Module
What's New in 2.0
SQL Injection
Cross-Site Scripting
Input/Data Validation
Code Access Security
Exception Management
Impersonation
Sensitive Data
Cryptography
Unsafe Code
Potentially Dangerous Unmanaged APIs
Auditing and Logging
Multi-threadingAdditional Resources

Security Question List: ASP.NET 2.0