Encoding Errors In Chinese Text From Xml?

Apr 23, 2012

I am creating xml files that contain chinese posts and it seemed to be working but I started getting an error:

This page contains the following errors:

error on line 4165 at column 25: Input is not proper UTF-8, indicate encoding ! Bytes: 0x0B 0xC3 0xA5 0xC2 Below is a rendering of the page up to the first error.

When trying to open some of the resulting files.The line it references contains chinese characters and this occurs only in some situations and my guess is that the text is sometimes containing some characters that throw it off. How can I ensure that the text for that field will always be properly encoded? I don't even understand why the issue yet.

Public Shared xwriter As XmlTextWriter = New XmlTextWriter(xmlfile, Encoding.UTF8)

I make sure the xmltextwriter is properly declared.

EDIT:

The issue is that I use vb.net and apparantly it encodes everything in utf-16 so I assume this is fine. The problem is that the text I am receiving is probably double encoded or incorrectly encoded and I need to clean it before using it; so that my xml is valid.

EDIT:

so if I need to fix my data, my question is how can I detect what encoding is used for a specific text and how do I convert into utf8 format that can be viewed in an xml file and make the file valid.

View 1 Replies


ADVERTISEMENT

VS 2010 Chinese Encoding Causing Invalid Xml?

Apr 23, 2012

I am creating xml files that contain chinese posts and it seemed to be working but I started getting an error:This page contains the following errors:error on line 4165 at column 25: Input is not proper UTF-8, indicate encoding !Bytes: 0x0B 0xC3 0xA5 0xC2

Below is a rendering of the page up to the first error.When trying to open some of the resulting files.The line it references contains chinese characters and the error occurs only for some posts and my guess is that the text has some encoding issues.

Public Shared xwriter As XmlTextWriter = New XmlTextWriter(xmlfile, Encoding.UTF8)

I make sure the xmltextwriter is properly declared and set the encoding and from what I understand is that vb.net encodes everything in utf-16. My code works well with streams I get from another source that sometime contains chinese characters and it never invalidates the xml. I tried cleaning the text using the following functions and the xml is now valid but when viewing the xml in the browser the characters are not chinese but junk.

Private Shared Sub replaceIllegalXMLChars(ByRef tempstring As String)
'remove any hexdecimal characters like  and �
tempstring = Regex.Replace(tempstring, "&#x([0-9A-F]{1}[0-9A-F]{0,1});", " ")

[code]....

so if I need to fix my data, my question is how can I detect what encoding is used for a specific text and how do I convert it into utf8 format that can be viewed in an xml file and make the file valid.

EDIT: I messed around with converting from one type to another, first ASCII to UTF8, then Unicode to UTF-8. did not work. The only time the xml is valid is when characters display as such:

油价,老百姓心�*永远的痛! � 民生、控物价一边说,油价一边涨,国家真得是为了老百姓的民生� �?

View 1 Replies

How To Display Ascii (chinese) To Chinese Unicode In Textbox Control

Feb 24, 2009

i have search for the whole forum and google but found no trace on converting from a ascii chinese character to unicode chinese character in .net control

View 2 Replies

EnCoding Message To DDE Client Using System.Text.Encoding.ASCII.GetBytes (message)?

Oct 28, 2009

I am sending a DDE message to a client using System.Text.Encoding.ASCII.GetBytes(item) . However, before the message is actually sent, I would like to get the message coded where if the item="Ask" then item=Ask (string variable) and so on. The code is:

Protected Overrides Function OnRequest(ByVal conversation As DdeConversation, ByVal item As String, ByVal format As Integer) As RequestResult
' Return data to the client only if the format is CF_TEXT

[code]....

View 3 Replies

Save Chinese AND English From RichTextBox To Text File And Load/parse File Back Into RichTextBoxControl?

Nov 19, 2010

# TAG NAME = is saved to a file using the code below but when I load that same file back into a RichTextbox Control using additional code below, I get inconsistent results as I try to parse the text. Has anyone else had this problem?'Save the contents of the RichTextBox into the file.richTextBox.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText);'Retrieve contents of File into RichTextBox control Dim logData As String
logData = System.IO.File.ReadAllText(path + "\" + filenname);

View 2 Replies

C# - Text Encoding (In .Net)

May 3, 2011

I have done very little with encoding of Text. Truthfully, I don't really even know what it means exactly.

For example, if I have something like:

CODE:

Is that 'encoded' in memory in a particular format? Does that format depend on what language I'm using?

If I were in another country, like China, for example, and I had a string of Chinese (mandarin? My apologies if I'm using the wrong words here) would the following code (that I've used fine on English strings) still work the same?

CODE:

Or would it lose all meaning when you convert that .Net string to a UTF8Encoding when that conversion isn't valid?

Finally, I've worked with .Net for a few years now and I've never seen, heard, or had to do anything with Encoding. Am I the exception, or is it not a common thing to do?

View 3 Replies

.net - Writing A Text File (Encoding)?

Aug 21, 2009

I am writing an application that must generate a plain Text file with fixed sized columns.my current code is:

Dim MyFilePath As String = Path & FILE_PREFIX & FileNr & ".TXT"
IO.File.Delete(MyFilePath)
Dim FileStr As New IO.StreamWriter(MyFilePath, False, <ENCODER HERE>)

[code].....

View 3 Replies

Create MailMessage Text Encoding?

Mar 8, 2010

I have an ASP.Net app that allows a user to write text into a Telerik RadEditor control and then send an email.For some reason I'm sometimes getting strange characters showing up in the email that is generated.se if I use the later, the text would show up just fine. If I pull up the saved record within the ASP.Net apps interface it looks just fine. It also appears just fine when I view the text within the recorded of the MS SQL table it was stored in. Continued--->I have tried to add it to the constructor of my email class with/without mybase but that had no effect.

Public Sub New(ByVal EmailDate As DateTime, ByVal LogoPath As String)
MyBase.New()
MyBase.BodyEncoding = Encoding.GetEncoding("iso-8859-1")

[code].....

View 2 Replies

System.Text.Encoding Not Working?

Nov 1, 2010

I can't use System.Text.Encoding, I get this error when trying to use it:

A first chance exception of type 'System.NullReferenceException' occurred in WindowsApplication3.exe
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

this is the

Private _TextEncoding As System.Text.Encoding
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _DownloadedBytes() As Byte = _TextEncoding.GetBytes("teststste")

[code]....

and then it exit function.

View 1 Replies

WriteAllText To Set The Encoding For A Text File

Mar 7, 2011

I used WriteAllText to set the encoding for a text file. When I wrote it, everything worked out fine. However, strange characters or symbols appeared in some ofm y fields without my having typed it. why is this so? The encoding I'm using is UTF8. I used the WriteAllText to write the fields to file but did not use the ReadAllText to bring the data back into the fields or program.

View 2 Replies

System.Text.Encoding Runs Asynchronous?

Jun 12, 2010

I recently worked on a small-scale EPP Client, which is a communications protocol over TCP/IP using XML packets to exchange commands and responses. The server I'm working with specifically is employing SSL so the code contains references to an SSLStream certificates and passphrases - please don't ask me to post more code than I provide here.We're building the XML EPP Commands in raw System.Strings, then using System.Text.Encoding.UTF8.GetBytes on the string to populate a Byte Array, then writing the Byte Array into the SSLStream. The server would communicate, negotiate certificates, and

View 10 Replies

VB 2010 - Text Reader Encoding And TextFieldParser

Apr 1, 2011

I have a VB2010 project where I need to read a tab delimited 50MB file using Microsoft.VisualBasic.FileIO.TextFieldParser. This technique works fine until the reader encounters a Unicode character upon which it inserts the little square thingy. The obvious choice is to change the encoding of the reader to Unicode from the default. This would probably work fine but for most files but this one is fairly large and I get the error TextFieldParser is unable to complete the read operation because maximum buffer size has been exceeded. By the way this file can be read completely without the Unicode option. Making the file smaller or breaking it up really isn't an option. Is is possible to increase the buffer size or is there another way to read this data that places the data in fields like the textparser and allows unicode characters?

View 9 Replies

ComboBox Set To OwnerDrawVariable Causes Item Text Mis-encoding End Displaying Blocks?

Apr 30, 2012

I have a problem with combobox. I set the DrawMode into OwnerDrawVariable so I can draw items seperately with styles, but the characters of the items are now displaying blocks. The block characters are none ASCII. It used to display well but not now and I don't know what caused it to happen. I didn't change my system locale. At the same time, other combobox that have Normal DrawMode displays nicely fine.

My custom drawing code:

e.Graphics.DrawString(combo.Items(e.Index), combo.Font, b2, rect.X, rect.Y)

View 6 Replies

Translate From Chinese To Braille?

Jul 1, 2011

How to translate from Chinese to braille?

View 3 Replies

Use Chinese Input In Project?

May 5, 2009

I have to make a virtual keyboard with my application which needs to input Chinese characters.

I can change the input language to Chinese, but cannot input Chinese coding as normal keyboard does...(I am using SendKeys.Send("A") as if I am pressing the "A" key on the keyboard, but the focus is on my virtual keyboard (another form other than the form of editing).)

any solution which I can get the virtual keyboard and the main task in the same application?

View 1 Replies

VS 2005 .Net With Chinese Character?

Dec 21, 2009

Recently, I handover the project which includes Chinese Characters on Form.But in my PC, these characters are display as "Square".So, can I know which font file I'm missing by checking the project contents file??And if I deploy with a set up exe to user, will this font file pack together? or i should manually insert this font in user PC?

View 8 Replies

Anyway To Read Text File With UTF-8 Encoding Using Streamreader Or File Stream

Jun 21, 2010

i would like to ask is there anyway to read a txt file with UTF-8 encoding using streamreader or filestream. the txt file is contain some extended ASCII that makes me cannot read the characters properly. I hav tried Encoding.ASCII.GetString(Encoding.UTF8.GetBytes()) but still it return wrong character when it's reading extended ASCII code.

View 2 Replies

Chinese Characters Website WebClient?

Mar 11, 2011

theEnchancedWinClient.WebClient.DownloadStrin20050601/n225789219.shtml")
will produce garbages.

[code].....

View 2 Replies

Encode/Decode Chinese Characters?

Nov 10, 2011

I have a call to Server.URLEncode(string) from an old asp file that stores user input into a table. In this case it was a string of Chinese charters.

The actual data is :

%E8%B0%B7%E6%AD%8C%E7%9A%84%E5%89%8D%E6%99%AF%E9%BA%A6%E5%85%8B%E6%96%AF%E9%9F%A6

I rewrote the code to vb.Net and after I get the data from the table, I call

HttpContext.Current.Server.UrlDecode(string) to decode the string, add it existing mark up for an email and send it on its way.

Note that with Visual Studio i can see the HTML markup as it appears in the email, and ALL of the Chinese data is EXACTLY as I would expect it.

When the emial is received i get "???????????" characters where there should be the Chinese characters.

What I do not understand:

What Server.URLEncode actually encodes the data to. It appears to be HEX.

What the array of "?" means in outlook or any other email system that opens it, I assume it means "Hey i cant convert this stuff, so here is a question mark for kicks, good luck."

View 6 Replies

Hindi Or Chinese Font In Windows App?

May 20, 2010

i want to type the hindi text in textbox and i want to insert the data in to sql server dataabse in hindi format.how can i do this in windows app?

View 4 Replies

Using Webclient To Read Chinese Characters

Jun 30, 2011

The resulting effect is that the characters are garbled.I've been looking around and there doesn't seem to be any solution.

View 1 Replies

Get VB To Publish The Text Files With The Program So That No Errors Can Occur

Apr 11, 2011

When I publish the program. Is there any way to get VB to publish the text files with the program so that no errors can occur. When I install and run the published program I get a series of errors relating to text files that are not found.

View 4 Replies

Detect Chinese Character In A String Program?

Nov 30, 2011

Is there a way to detect a Chinese character in a string which is build like this:

dim test as string = "letters 中國的"

Now I want to substring only the Chinese characters. But my code is database driven, so I can't substring it, because the length is always different. So is there a way I can split the string, from the moment I detect a Chinese character?

View 1 Replies

VS 2008 Convert Chinese Char To Pinyin?

Jun 4, 2011

is there any way to convert chinese characters to pinyin?i searched google and this is the nearest result that i found[URL]..HttpUtility.HtmlEncode(Text);

but it requires .net framework 4 if i'm not wrong.

currently i am using .net framework 3.5. is there any other way or web service that i can use?

View 1 Replies

Why Chinese Windows Would Save As ANSI Instead Of Unicode

Mar 3, 2010

I have an application that saves some text to a text file as unicode. When I run the application on a US English windows XP everything is fine, but when running on a system with Chinese version of XP, the file is saved as ANSI. Below is a code snippet showing UnicodeEncoding Does anyone know why Chinese Windows would save as ANSI instead of unicode?

Dim info As Byte() = New System.Text.UnicodeEncoding().GetBytes(txtScenDetails.Text)
fs.Write(info, 0, info.Length)

View 1 Replies

ASP.NET UpdatePanel Timeout And 500 Errors With Custom Errors?

Sep 23, 2011

I have a .net application that uses customerrors web.config module to display meaningful messages for errors. It works without any issues for 500 errors/exceptions caused by non-ajax and ajax components (updatepanel). However, in a scenario where updatepanel's asynchronous request times out, there is no error raised at all. I was able to see the timeout in firebug and come up with a solution that would at least display the error message as an alert and then redirect the user to the 500 error page using javascript but it's not quite doing what the rest of the application does in case of an unhandled errors like these. I basically just want everything to go through "LogEvent" mechanism so based on the severity of the error, it does the necessary work.This 500 error page doesn't have anything in the Server.GetLastError() for these timeout scenarios. Is this an expected behaviour? Can it be changed so I do have access to these timeouts in Server.GetLastError() OR maybe just run this error through "LogEvent" mechanism? Is there a better/more graceful way to handle this issue?

Below is my code to give you an idea, not exactly what I have in my application but pretty close.

Web.Config
<customErrors mode="On" defaultRedirect="~/Errors/ErrorUnknown.aspx" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="~/Errors/Error500.aspx" />
</customErrors>

[code]....

View 1 Replies

Add String Table For Chinese Language In Resource File (*.res In VB6)

Sep 7, 2009

How can we add multiple columns in resource file (.res) for multi language (eg. 1st column for English and 2nd column for Chinese) through script used by rc.exe utility? We know how to add one column to resouce file using script and compile it with rc.exe it will generate one default language column with id,

[Code]...

View 1 Replies

C# - Excel Download For Chinese Printing Unwanted Characters?

Jan 17, 2011

I am trying to download chinese data from database to excel. But data is coming with different charecters in Excel like this Here is the my code for download excel. I don't understand what's wrong in my code.

[Code]...

View 1 Replies

Using Word Interop SaveAs To Save A Text File Results In Errors

Nov 15, 2010

My application crashes when trying to save a word document as text. The error at SaveAs is "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))" I am opening and manipulating a Word 2003 Document (using Word 2007) and then trying to save it as a text file.

[Code]...

View 2 Replies

Sql Server 2005 :: Output Chinese Charactes From SQL Database Correctly?

Jan 15, 2010

I have a nvarchar(256) field in a SQL 2005 database table that contains several records in Chinese and I'd like to output this characters correctly in VB.NET code.What I have now doesn't work at all:

Dim MyText As String =
Dim value As [String] = MyText
Dim tc As Encoding = Encoding.GetEncoding(950)

[code].....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved