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.EventArg s) Handles MyBase.Load
Response.Clear( )
Response.Conten tType = "text/xml"
Response.Conten tEncoding = Encoding.Unicod e
...
buildNodeRSS(Re quest.QueryStri ng("pageID"))
...
End Sub
Public Sub buildNodeRSS(By Val 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(sit eID)
XMLfile = theMenu.strMenu
'check to see if the file exists in the cache
If System.Web.Http Context.Current .Cache(siteID & "menuXML") Is Nothing Then
'read in the XML file
Dim theMenuXML As menuXML = retrieveMenuXML .getMenuXML(sit eID)
XMLfile = theMenuXML.strM enu
'add the text to the cache object and set timeout
System.Web.Http Context.Current .Cache.Insert(s iteID & "menuXML", XMLfile,
Nothing, DateTime.Now.Ad dMinutes(0.5), TimeSpan.Zero)
Else
'just use the cached version
XMLfile = CType(System.We b.HttpContext.C urrent.Cache(si teID & "menuXML"),
String)
End If
styleSheetFile = "lastUpdatesRSS .xslt"
Dim stylesheet As String = (MapPath(styleS heetFile))
'Create the XslTransform and load the stylesheet.
Dim xslt As XslTransform = New XslTransform
xslt.Load(style sheet)
'Load the XML data file.
Dim doc As XPathDocument = New XPathDocument(s r)
'Create an XsltArgumentLis t.
Dim xslArg As XsltArgumentLis t = New XsltArgumentLis t
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.ReadTo End().ToString)
End Sub
--
=============== =============== =============== =============== =====
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA