D
darrel
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
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