Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Serializing XML with stylesheet
Message
From
20/08/2012 09:43:53
 
 
To
20/08/2012 09:13:14
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01550792
Message ID:
01550796
Views:
32
This is what I come up:
        ' Add a stylesheet
        ' expC1 Url
        Public Function AddStylesheet(ByVal tcUrl As String) As Boolean
            Dim lcText As String = ""
            Dim lcUrl As String = ""
            Dim llSuccess As Boolean = False
            Dim loMemoryStream As MemoryStream = New MemoryStream()
            Dim loXmlDocument As XmlDocument = New XmlDocument()
            Dim loXmlProcessingInstruction As XmlProcessingInstruction = Nothing
            Dim loXmlTextWriter As XmlTextWriter = Nothing

            ' Reset everything
            cMessage = ""

            ' Initialization
            lcUrl = tcUrl

            ' Trim everything
            lcUrl = Trim(lcUrl)

            Try

                ' Now load the in-memory stream XML data into the XML document
                loMemoryStream.Seek(0, SeekOrigin.Begin)
                loXmlDocument.Load(loMemoryStream)

                ' Now add the stylesheet processing instruction to the XML document
                lcText = "type=""text/xsl"" href=""" + lcUrl + """"
                loXmlProcessingInstruction = loXmlDocument.CreateProcessingInstruction("xml-stylesheet", lcText)

                loXmlDocument.InsertAfter(loXmlProcessingInstruction, loXmlDocument.FirstChild)

                ' Now write the document out to the final output stream
                loXmlTextWriter = New XmlTextWriter(oMemoryStream, System.Text.Encoding.ASCII)
                loXmlDocument.WriteTo(loXmlTextWriter)
                loXmlTextWriter.Flush()

                llSuccess = True
            Catch loError As Exception
                cMessage = loError.Message
            End Try

            Return llSuccess
        End Function
oMemoryStream already exists as part of the class and is initialized when this method is called. This is pretty much as simplified as I could see unless there is something new since the last six years which would be better.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform