0

A web service returns an xml string with french text in it. When printing the xml node

 xmlResponse.LoadXml(resp);
 XmlNode Text = xmlResponse.SelectSingleNode("/res/Text");
 sMessageText = Text.InnerText;

the text looks like this:

e.g. Le nom de le propri�taire de carte doit �tre entre 4 et 32 caract�res

How do I encode it? How do I show readable text.

Thank you

Garett
  • 16,632
  • 5
  • 55
  • 63
Benk
  • 1,284
  • 6
  • 33
  • 64
  • 1
    You can use the [System.Text.Encoding](http://msdn.microsoft.com/en-us/library/system.text.encoding%28v=VS.100%29.aspx) to convert the text, but are you creating this XML or consuming from somewhere else? because you shouldn't need to do any conversion, if your xml have the correct encoding. – thiagoleite Dec 01 '11 at 17:14
  • the xml response is coming from another system. I was just thinking maybe I have to capture the xml response some other way... currently I am using LoadXml. string resp = Calling webservice.... xmlResponse.LoadXml(resp); – Benk Dec 01 '11 at 17:53

2 Answers2

0

You might have to set the cultureinfo of the control that is to use the string, i'm not sure of which property but you should assign it to CultureInfo("fr-FR");

Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
0

I dont think there is a method out of the box in XmlDocument class to load and convert the encoding. You can try the following, its from the link i gave you, the documentation for System.Text.Encoding:

  Encoding ascii = Encoding.ASCII;
  Encoding unicode = Encoding.Unicode;

  // Convert the string into a byte array.
  byte[] unicodeBytes = unicode.GetBytes(unicodeString);

  // Perform the conversion from one encoding to the other.
  byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

  // Convert the new byte[] into a char[] and then into a string.
  char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
  ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
  string asciiString = new string(asciiChars);

You just need to change it for the encodings you're using. Also you might want to check this question, it has many answers that might help you.

Community
  • 1
  • 1
thiagoleite
  • 503
  • 1
  • 3
  • 11