Skip to Content
avatar image
Former Member

HTML Entity Escape Character Conversion

Requirement is to Convert UTF-8 encoded Speciual language characters to HTML Entity Escape Character's. For example In the source I have a Description field with value "Caractéristiques" which is 'Characteristics' in French, This needs to be converted to "Caractéristiques" when sent to the Reciever.i.e the Special Language Symbols like é = é (in HTML Entity format.)

Below is the Link for a List of HTML Entity Char's

http://www.theukwebdesigncompany.com/articles/article.php?article=11

could anybody please suggest how this can be achieved in mapping...any UDF or Encoding techniques...?

many Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 07, 2008 at 09:40 AM

    Hi Veera

    this is ajay

    code for ur problem

    String ToHTMLEntity(String s) {
    		StringBuffer sb = new StringBuffer(s.length());
    
    		boolean lastWasBlankChar = false;
    		int len = s.length();
    		char c;
    
    		for (int i = 0; i < len; i++) {
    			c = s.charAt(i);
    			if (c == ' ') {
    				if (lastWasBlankChar) {
    					lastWasBlankChar = false;
    					sb.append(" ");
    				} else {
    					lastWasBlankChar = true;
    					sb.append(' ');
    				}
    			} else {
    				lastWasBlankChar = false;
    				//
    				// HTML Special Chars
    				if (c == '"')
    					sb.append("&quot;");
    				else if (c == '&')
    					sb.append("&amp;");
    				else if (c == '<')
    					sb.append("&lt;");
    				else if (c == '>')
    					sb.append("&gt;");
    				else if (c == '
    ')
    					// Handle Newline
    					sb.append("&lt;br/&gt;");
    				else {
    					int ci = 0xffff & c;
    					if (ci < 160)
    
    						sb.append(c);
    					else {
    
    						sb.append("&#");
    						sb.append(new Integer(ci).toString());
    						sb.append(';');
    					}
    				}
    			}
    		}
    		return sb.toString();
    	}

    rewrd points if it help u

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 04, 2008 at 02:04 PM

    i suppose there are special converting java functions where you can convert entire string to utf-8 and from utf-8.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 04, 2008 at 11:34 PM

    There is no support for this in PI.

    I think the best way is writing a Java Mapping.

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 07, 2008 at 09:52 AM

    what about this:

    String win1251String = "STRING IN_WINDOWS-1251";
    String utf8String= new String(win1251String.getBytes(“windows-1251”),”utf-8”);
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 07, 2008 at 12:41 PM

    Hi Veeranjaneyulu.P ,

    there are certain special characters that are not supported by UTF 8 encoding . For ex: foreign language characters

    for this you can follow this link

    http://www.dpawson.co.uk/xsl/characters.html

    so i suggest you to use ISO encoding in place of UTF 8 encoding

    In your receiver communication channel under text XML payload manipulation there is a field XML code , there you can define the coding you want fro example UTF 8 or ISO encoding

    here if you will give ISO encoding in this field of receiver channel. then your output file may contain special characters such as foreign characters also

    Hope this may solve your problem

    Thanks

    sandeep

    PS : if helpful kindly reward points

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 11, 2008 at 02:20 PM

    Hi All,

    Thanks for suggetions.., 😊

    Add comment
    10|10000 characters needed characters exceeded