473,657 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to grab data as UTF-8 rather than UTF-16 from DB?

I'm having a really odd problem that I can't find many other examples of.

I'm using XMLTextWriter and grabbing data from a database and then spitting
out an RSS-compliant XML file.

The problem I have is that, by default, IE pukes on it.

If I output the XMLTextWriter as:

XmlTextWriter(R esponse.OutputS tream, Encoding.UTF8)

And let the page headers default, I end up with a UTF8 page encoding, but
the XMLtextWriter spits out the XML as such:

<?xml version="1.0" encoding="utf-16"?><rss version="2.0">. ..

IE doesn't like this as the XML encoding doesn't match the page encoding.

So, if I force the page to also be UTF-16, then both encodings match, but
apparently IE can't handle UTF-16, period. So I still get parsing errors
when loading the XML in the browser (there's a space between each and ever
character in the XML).

It appears that my solution is going to have to be to just make sure the
content from the DB is being retrieved as UTF-8 forcing everything to be
UTF-8. But I'm not sure how to do that. Can it be done?

-Darrel

Apr 13 '07 #1
5 1283
darrel wrote:
I'm having a really odd problem that I can't find many other examples of.

I'm using XMLTextWriter and grabbing data from a database and then spitting
out an RSS-compliant XML file.

The problem I have is that, by default, IE pukes on it.

If I output the XMLTextWriter as:

XmlTextWriter(R esponse.OutputS tream, Encoding.UTF8)

And let the page headers default, I end up with a UTF8 page encoding, but
the XMLtextWriter spits out the XML as such:

<?xml version="1.0" encoding="utf-16"?><rss version="2.0">. ..

IE doesn't like this as the XML encoding doesn't match the page encoding.

So, if I force the page to also be UTF-16, then both encodings match, but
apparently IE can't handle UTF-16, period. So I still get parsing errors
when loading the XML in the browser (there's a space between each and ever
character in the XML).

It appears that my solution is going to have to be to just make sure the
content from the DB is being retrieved as UTF-8 forcing everything to be
UTF-8. But I'm not sure how to do that. Can it be done?
Even if it was possible, that would not help you at all. Strings in .NET
are handled as 16 bit unicode, so however you recieve the data from the
database, it would be converted into 16 bit string data.

That the string data is 16 bits internally doesn't affect the encoding.
What ever encoding you use, the string data will be encoded before
output, the internal representation of strings are never output directly.

Set the Response.Conten tEncoding property to UTF-8 also, and see if that
helps.

Another thing that might work is to use null for encoding when creating
the XmlTextWriter. This will output UTF-8 data, but omit the encoding
from the processing instruction in the XML.

--
Göran Andersson
_____
http://www.guffa.com
Apr 13 '07 #2
Set the Response.Conten tEncoding property to UTF-8 also, and see if that
helps.
It doesn't. That's the problem.

The issue is that even though I set the XMLtextWriter to output UTF-8, it
doesn't, and still appends a UTF-16 XML header.
Another thing that might work is to use null for encoding when creating
the XmlTextWriter. This will output UTF-8 data, but omit the encoding from
the processing instruction in the XML.
What is the syntax for that? This doesn't work:

Dim objX As New XmlTextWriter(R esponse.OutputS tream, Encoding.null)

-Darrel
Apr 13 '07 #3
darrel wrote:
>Set the Response.Conten tEncoding property to UTF-8 also, and see if that
helps.

It doesn't. That's the problem.

The issue is that even though I set the XMLtextWriter to output UTF-8, it
doesn't, and still appends a UTF-16 XML header.
>Another thing that might work is to use null for encoding when creating
the XmlTextWriter. This will output UTF-8 data, but omit the encoding from
the processing instruction in the XML.

What is the syntax for that? This doesn't work:

Dim objX As New XmlTextWriter(R esponse.OutputS tream, Encoding.null)
Dim objX As New XmlTextWriter(R esponse.OutputS tream, null)

--
Göran Andersson
_____
http://www.guffa.com
Apr 13 '07 #4
Dim objX As New XmlTextWriter(R esponse.OutputS tream, null)

VS.net doesn't like that either. It's telling me 'Null is not delcared'

I guess a different question is why does it output utf-16 even when I tell
it to use encoding.utf8?

-Darrel
Apr 13 '07 #5
darrel wrote:
>Dim objX As New XmlTextWriter(R esponse.OutputS tream, null)

VS.net doesn't like that either. It's telling me 'Null is not delcared'
Sorry. In VB you use Nothing instead of null.
I guess a different question is why does it output utf-16 even when I tell
it to use encoding.utf8?
I think that the HttpResponseStr eam object might have an encoding
internally. The same problem occurs if you create an XmlTextWriter that
uses a StringWriter that uses a StringBuilder, as observed in this thread:

http://www.devnewsgroups.net/group/m...opic60955.aspx

To prevent this, you can create an XmlTextWriter that uses a
MemoryStream, that way there is no encoding in the stream that will
affect the XmlTextWriter. Use Response.Binary Write to output the
contents of the MemoryStream.

--
Göran Andersson
_____
http://www.guffa.com
Apr 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1365
by: Andy Kasotia | last post by:
On the client once the user clicks the Submit button....in my code the following javascript function kicks off... onclick="return SubmitForm('frmCurrBuildings', 'CurrBuildings.asp', c_iLOADNEW, '_self')" function SubmitForm( FormName, ActionASP, ActionVal, TargetVal ) eval( "document." + FormName + ".target = '" + TargetVal + "'" ) ; eval( "document." + FormName + ".action = '" + ActionASP + "?Action=" + ActionVal + "'" ) ; eval(...
3
1289
by: Mike L | last post by:
This is in a WinForm. How do I grab all the data in all the cells of the row the user selected OR all the data in all the cells if the user selects one of the cells in the row? What event should I put the code in?
2
9642
by: K.H. | last post by:
Hi Does anyone know how I can grab a video stream from an IP-address? There's a video web server for live image transmission in the Internet. Data transfer is accomplished via TCP/IP. The web cam that I am using is integrated into a network with fixed IP address. The streaming software is already there, so I have to go to this IP-address to see the live video stream. How can I grab this video stream from an IP-address with an application...
8
9411
by: '69 Camaro | last post by:
Perhaps I'm Googling for the wrong terms. Does anyone have links to examples of the syntax necessary to read the HTML on another Web page when that HTML is produced from JavaScript using the document.write( ) method? For a simplified example, I have two Web pages. Page 1 uses JavaScript with the following: htmlData = "<B>This is bold text.</B>"; document.write(htmlData);
1
2002
by: Zak | last post by:
Hello, I need some help trying to grab the data selected from a checkboxlist. The checklist is acting like a menu. The first selection is accepted but not the multiple ones. For example is the user selects "Checked Baggage" the selection is stored the correct procedure is processed, but if the user selects "SIDA" along with the "Checked Baggage" there is no stored data, just that first selection. Just the first entry is saved. Can...
0
953
by: Grey | last post by:
i need to grab the pdf content. the pdf content has the standard format with data inside. is there any way to 1) grab the table content in pdf format; and then 2) put the data into excel
2
1948
by: kazi | last post by:
Hi all I need to know, how to grab html data using perl code? we have a two web server. Now I need to grab the one perticular page data and put the data in a table. Please help me how to do this. Kazi
19
1867
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a href='". $file_name."&order_by=carnumber'>Carnumber</a></th> <th><a href='". $file_name."&order_by=location'>Location</a></th> <th><a href='". $file_name."&order_by=sighting_date_asc'>Sighting
6
1982
by: blanderk | last post by:
Dear all, i need some help here. currently i have 1 table with multiple field. 1 of the field name PackSize contain data like ;;5000;ml;; or ;;;;60;Tablet etc. So, i want to ask expert out there,how to grab the value inside PackSize into my other field such as field Vol,Volunit,VolDnm,VolDnmUnit,Package,PackageUnit. here some example :
5
2478
by: goldenteeplanet | last post by:
void reverse( node * & s) { // NOTE: YOU CAN NOT MOVE DATA FROM ONE NODE TO ANOTHER // YOU CAN ONLY MOVE POINTERS FROM ONE NODE TO ANOTHER // Grab the first node` // Create startNode = s; node *guest,*secondToLast,*secondElem;
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.