473,395 Members | 1,535 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,395 software developers and data experts.

I need UTF-8. But I keep getting UTF-16. Why? How to fix?

I've been struggling for some time now getting a RSS app to work. I'm
creating RSS from existing XML files (transforming via XSLT).

The problem is that the page, itself, is still being sent at UTF-16 when I
create the RSS from XSLT. It's UTF-8 when I'm creating the XML myself via
the DB and an XMLTextWriter.

This gives IE headaches. It adds a space between each character in the XML
and doesn't render it as an XML file.

I'm completely lost as to what, exactly, is causing the page to be sent as
UTF-16 and how/where to fix it. The key code is below:
==========================================

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Clear()
Response.ContentType = "text/xml"
Response.ContentEncoding = Encoding.Unicode

...
buildNodeRSS(Request.QueryString("pageID"))
...

End Sub
Public Sub buildNodeRSS(ByVal pageId As Integer)

Dim siteID As Integer
' query the DB to find out which site this particular node belongs to
....code to grab the siteID...
End Try
' set up the XML file
Dim XMLfile As String
theMenu = retrieveMenuXML.getMenuXML(siteID)
XMLfile = theMenu.strMenu


'check to see if the file exists in the cache
If System.Web.HttpContext.Current.Cache(siteID & "menuXML") Is Nothing Then
'read in the XML file
Dim theMenuXML As menuXML = retrieveMenuXML.getMenuXML(siteID)
XMLfile = theMenuXML.strMenu
'add the text to the cache object and set timeout
System.Web.HttpContext.Current.Cache.Insert(siteID & "menuXML", XMLfile,
Nothing, DateTime.Now.AddMinutes(0.5), TimeSpan.Zero)
Else
'just use the cached version
XMLfile = CType(System.Web.HttpContext.Current.Cache(siteID & "menuXML"),
String)
End If

styleSheetFile = "lastUpdatesRSS.xslt"
Dim stylesheet As String = (MapPath(styleSheetFile))
'Create the XslTransform and load the stylesheet.
Dim xslt As XslTransform = New XslTransform
xslt.Load(stylesheet)

'Load the XML data file.
Dim doc As XPathDocument = New XPathDocument(sr)

'Create an XsltArgumentList.
Dim xslArg As XsltArgumentList = New XsltArgumentList

xslArg.AddParam("pageID", "", pageId)
'create the default link prefix param
Dim linkPrefix As String

linkPrefix = "/"

xslArg.AddParam("linkPrefix", "", linkPrefix)

Dim ms As MemoryStream = New MemoryStream
xslt.Transform(doc, xslArg, ms, Nothing)
ms.Position = 0
Dim StReader As StreamReader = New StreamReader(ms, Encoding.UTF8)
'Response.Write(sw.ToString)
Response.Write(StReader.ReadToEnd().ToString)
End Sub

--
================================================== ===============
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
Apr 30 '07 #1
1 1179
Response.ContentEncoding = Encoding.Unicode

I'm a moron. I've been staring at the above for a while and didn't notice
that 'duh...I'm SETTING it to UTF-16 via unicode'.

Encoding.utf-8 fixed it.

-Darrel
Apr 30 '07 #2

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

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
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...
0
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...
0
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...

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.