ethar turky
asked on
api.microsofttranslator.com return some html
Dear all,
I Use api.microsofttranslator.co m web service as base of my web services.
The translated value is returned like this
I just need to return the translated word only (User) that why I use this code:
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.
I Use api.microsofttranslator.co
The translated value is returned like this
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">¿¿¿¿¿¿¿¿</string>
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;
But it return :<html><head></head><body>¿¿¿¿¿¿¿¿</body></html>
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.
ASKER
Thanks for your reply,
Yes for sure my problem in encoding, but how to solve it?
Context.Response.ContentEn coding = System.Text.Encoding.GetEn coding("IS O-8859-1") ; // I try utf-8 and GetEncoding("ISO-8859-1");
Context.Response.Output.Wr ite(xTrans lation.Inn erText.ToS tring() ); //xTranslation.InnerText
Context.Response.End();
return string.Empty;
Yes for sure my problem in encoding, but how to solve it?
Context.Response.ContentEn
Context.Response.Output.Wr
Context.Response.End();
return string.Empty;
did u check the examples of the api.microsofttranslator.co m?
which method are u using ? ajax,http or soap ?
which method are u using ? ajax,http or soap ?
ASKER
I use this:"
When I use above method it return XML with correct encoding.
but when I use :
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());
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;
to prevent xml and show the information (translation ) only I got bad encoding
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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