簡體   English   中英

asp.net XML:讀取xml節點並顯示編碼的文本

[英]asp.net XML: reading xml node and displaying encoded text

Web服務返回其中包含法語文本的xml字符串。 打印xml節點時

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

文本如下所示:

例如,第4號和第32號法定所有權書

如何編碼? 如何顯示可讀文本。

謝謝

您可能必須設置要使用字符串的控件的Cultureinfo,我不確定哪個屬性,但應將其分配給CultureInfo("fr-FR");

我認為XmlDocument類中沒有開箱即用的方法可以加載和轉換編碼。 您可以嘗試以下方法,它來自我給您的鏈接,即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);

您只需要更改其使用的編碼即可。 另外,您可能想檢查一下這個問題 ,它有許多答案可能會對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM