473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with encoding

4
Hi!
I'm a web services developer and there are some bugs about encoding. Point is that my web service is using people from countries with different encodings (russian - windows-1251, baltic - windows-1257, ect).
At first i encoding problem solved easely because data from database returned into dataset type. I used code like this (simpled):

Expand|Select|Wrap|Line Numbers
  1. ...
  2. Dim Com As New SqlCommand
  3. Dim name As String
  4. Dim reader As SqlDataReader = oCmd.ExecuteReader(CommandBehavior.SequentialAccess)
  5. Do While reader.Read()
  6.       Dim spaceByteArray(0) As Byte
  7.  
  8.       'detect region language
  9.       If _region.Contains("RU") Then 'if russian
  10.             'read 'name'column data
  11.             retval = reader.GetBytes(5, 0, outbyte, 0, 255)
  12.             name = Encoding.GetEncoding("windows-1251").GetString(outbyte).Trim()
  13.       End If
  14. Loop
  15. ...
  16.  
I read each table row and column into byte array and then encoded into needed encoding.
But now i must encoding data what are returned from "FOR XML EXPLICIT" structure - XML document.
Question is - is it possible read (ExecuteXmlReader) concrete XML nodes and their values into byte array when reading from database how it do "ExecuteReader"?
Or there is other way to encode when reading, because when data is returned and writed into XMLDocument variable it is impossible to recognize and change it.
Thanks!
Mar 17 '08 #1
7 2401
Plater
7,872 Expert 4TB
Any string you can get, like from an XML file, can be converted to bytes with the Encoding ( .GetBytes() )
Once you have the bytes, you can re-convert to a string with a different Encoding type.

Note: There maybe a more direct way to do this, but that two step process should work.
Mar 17 '08 #2
Vipsis
4
There is that problem, that I must encode string then it is between database and XMLDataDocument variable, how I done with "name" variable into my example: read into byte array output from DB and after encoding convert it to string (with needed encoding) and only then assign to the "name".
If I encode string later, this specific encoder not recognize exact character code, because specific code are automatically coverted to Unicode, which are little bit different and result are question marks...
Mar 17 '08 #3
Plater
7,872 Expert 4TB
Have you used the System.Text.Encoding.Unicode object?
Mar 17 '08 #4
Vipsis
4
Have you used the System.Text.Encoding.Unicode object?
Yes, I used it, but without result.
Name (for example) are stored in DB how it must be - clear Russian and Baltic characters.
But when they are stored into VB.NET String data type variable, they represents as question marks, or some freaky symbols that aren't that I need.
When I didn't used "FOR XML EXPLICIT", I encoding done "by hand" at time when data has been read from DB.
It seems, that there no other way, I must stay at DataSet SequentialAccess :(
But now are one more question - is in Studio 2008 function like SQL "FOR XML EXPLICIT"?
Mar 18 '08 #5
Plater
7,872 Expert 4TB
Have you tried using the DataTable's abilities to auto-populate from an XML file?
Mar 18 '08 #6
Vipsis
4
Have you tried using the DataTable's abilities to auto-populate from an XML file?
:) No I'm not tried do do this, because I do not need it. Function output must be well encoded XML file. I need convert something encoded (dataset, for example) TO not FROM XML.
Mar 19 '08 #7
Plater
7,872 Expert 4TB
Well I'm no longer sure what you are doing?
A DataTable is capabale of writing TO and FROM an XML file, I would think you could supply an encoding scheme to it?
Mar 19 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Club-B42 | last post by:
i've compiled my programm using command "python setup.py py2exe >1" python script works fine, but .exe version fails with =====================================================================...
3
by: Tjerk Wolterink | last post by:
Helo i'v an xml file like this: <bestand> <id>8</id> <beschrijving type="string"><!]></beschrijving> <file type="file" mime-type-image="/xcm/mime_types/movie.gif"><!]></file> </bestand>
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
5
by: James Wong | last post by:
Dear all, I've a web service function and it contains a parameter in System.Text.Encoding. I found that the data type of this parameter in caller application becomes MyWebSvcName.Encoding...
2
by: Ali | last post by:
I am having problem compiling schema contained in WSDL file when analyzing schema types contained in it (for example http://www.ebout.net/net/GoogleSearch.wsdl). Following code demonstrates my...
4
by: Cott Lang | last post by:
ERROR: could not convert UTF-8 character 0x00ef to ISO8859-1 Running 7.4.5, I frequently get this error, and ONLY on this particular character despite seeing quite a bit of 8 bit. I don't really...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects"...
0
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
12
by: Punkis | last post by:
Hi all, I have a problem with my php and mysql project. I use an auctions software, named phpauction for my project. I import into my database with utf8 encodingm and I can see the greek...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.