[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

Show data of MemoryStream in a literal control

I am using the XMLtextwriter to create  XML data. The writer writes the data into a memorystream. Once it is finished I would like to show the XML data in a literal control, before I use an XSL file for a transformation.

My code:

        Dim oMemoryStream As New System.IO.MemoryStream
        Dim oXMLWriter As System.Xml.XmlTextWriter
        oXMLWriter = New System.Xml.XmlTextWriter(oMemoryStream, System.Text.Encoding.UTF8)

        With oXMLWriter
            .Formatting = System.Xml.Formatting.Indented
            .Indentation = 4
            .IndentChar = CChar(" ")
            .WriteStartDocument()
            .WriteStartElement("navigation")

            Call WriteNavigationItems(oXMLWriter, PageInfo.AtaChapterID)

            .WriteEndElement()
            .WriteEndDocument()
        End With

        oXMLWriter.Flush()

        oMemoryStream.Position = 0
        Dim XMLdoc As New XPathDocument(oMemoryStream)
        oMemoryStream.Close()

        Dim stylesheet As New XslTransform
        stylesheet.Load("E:\BA - Projects\Bright Alley\wwwroot\FE\ba_controls\default\navigation.xslt")

        Dim oStringWriter As New System.IO.StringWriter
        stylesheet.Transform(XMLdoc.CreateNavigator(), Nothing, oStringWriter, Nothing)
        ltlNavigation.Text = oStringWriter.ToString

        oXMLWriter.Close()
0
Kai77
Asked:
Kai77
  • 2
1 Solution
 
b1xml2Commented:
Dim memoryStream As New System.IO.MemoryStream
Dim writer As New System.Xml.XmlTextWriter(memoryStream, System.Text.Encoding.UTF8)

With writer
      .Formatting = System.Xml.Formatting.Indented
      .Indentation = 4
      .IndentChar = CChar(" ")
      .WriteStartDocument()
      .WriteStartElement("navigation")
      
      Call WriteNavigationItems(writer, PageInfo.AtaChapterID)
      
      .WriteEndElement()
      .WriteEndDocument()
End With

writer.Flush()

memoryStream.Position = 0
Dim reader As New StreamReader(memoryStream)
'getting the xml from the memory stream
Dim value As String = reader.ReadToEnd()
'now add that to your control

memoryStream.Position = 0
Dim document As New XPathDocument(memoryStream)

memoryStream.Close()
reader.Close()

Dim stylesheet As New XslTransform
stylesheet.Load("E:\BA - Projects\Bright Alley\wwwroot\FE\ba_controls\default\navigation.xslt")

Dim outputWriter As New System.IO.StringWriter
stylesheet.Transform(document.CreateNavigator(), Nothing, outputWriter, Nothing)
ltlNavigation.Text = outputWriter.ToString

writer.Close()
0
 
b1xml2Commented:
it is important to use the proper naming conventions. Avoid the Hungarian notation as whatever that applied in VB is not necessarily correct in VB.NET

All instances of classes are objects. Thus, there is no need to use the prefix o.

HTH
0
 
Kai77Author Commented:
Ok thanks man
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now