Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

api.microsofttranslator.com  return some html

Posted on 2014-02-26
5
Medium Priority
?
320 Views
Last Modified: 2014-04-03
Dear all,
I Use api.microsofttranslator.com web service as base of my web services.

The translated value is returned like this
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">¿¿¿¿¿¿¿¿</string>

Open in new window


 I just need to return the translated word only (User) that why I use this code:
				Context.Response.ContentEncoding = System.Text.Encoding.UTF8; 
				Context.Response.Output.Write(xTranslation.InnerText.ToString() ); 
				
				Context.Response.End();
				return string.Empty;

Open in new window

But it return :
<html><head></head><body>¿¿¿¿¿¿¿¿</body></html>

Open in new window


 just need the translated word not any thing else.

(btw the extra html returned only if I translate from English to Arabic , but if I translate from Arabic to English the only translated word are returned =As Required)
thanks.
0
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 39888527
It seems to be an encoding problem.

Returning data is unicode and ur data comes with utf-8. so u need to convert from utf to unicode to see in arabic. but u ave to do this conversion in byte not as string
0
 

Author Comment

by:ethar1
ID: 39898052
Thanks for your reply,
Yes for sure my problem in encoding, but how to solve it?
                        Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1")  ; // I try utf-8 and GetEncoding("ISO-8859-1");
                        Context.Response.Output.Write(xTranslation.InnerText.ToString() ); //xTranslation.InnerText
                        
                        Context.Response.End();
                        return string.Empty;
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 39899644
did u check the examples of the api.microsofttranslator.com?

which method are u using ? ajax,http or soap ?
0
 

Author Comment

by:ethar1
ID: 39904537
I use this:"
			string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + sText + "&from=" + sFrom + "&to=" + sTo;
			System.Net.WebResponse response = null;
			try
			{
				System.Net.WebRequest translationWebRequest = System.Net.WebRequest.Create(uri);
				translationWebRequest.Headers.Add("Authorization", headerValue);

				response = translationWebRequest.GetResponse();

				System.IO.Stream stream = response.GetResponseStream();
				System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); //
				System.IO.StreamReader translatedStream = new System.IO.StreamReader(stream, encode);
				System.Xml.XmlDocument xTranslation = new System.Xml.XmlDocument();
				xTranslation.LoadXml(translatedStream.ReadToEnd());
return (xTranslation.InnerText.ToString());

Open in new window


When I use above method it return XML with correct encoding.
but when I use :
				Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1")  ; // GetEncoding("ISO-8859-1");
				Context.Response.Output.Write(xTranslation.InnerText.ToString() ); //xTranslation.InnerText

				Context.Response.End();
				return string.Empty;

Open in new window

to prevent xml and show the information (translation ) only  I got bad encoding
0
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 2000 total points
ID: 39905597
when u check ur xml in the first code block is it correct ?
IF its correct then u must not convert it to 8859-1.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question