Go Premium for a chance to win a PS4. Enter to Win

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

using XMLTextWriter convert the xml tags to MemoryStream

I have the following code windows application

Dim ms As MemoryStream
ms = New MemoryStream

Dim xtw As New Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8)

xtw.Formatting = Formatting.Indented
xtw.Indentation = 2
xtw.QuoteChar = """"c
xtw.WriteStartDocument(True)
xtw.WriteComment("Data from CSI")
xtw.WriteStartElement("Data")
xtw.WriteStartElement("Employee")
xtw.WriteElementString("LastName", "Dillan")
xtw.WriteElementString("FirstName", "Bob")
xtw.WriteElementString("MiddleInitial", "E")
xtw.WriteEndElement()
xtw.WriteEndDocument()
xtw.Close()

I am using XMLTextWriter to fill the MemoryStream. What appears to be
happening is that the memory stream is getting filled. If I step through
this code and look at the length of (ms.length), it is always 0 (zero).

What am I missing? Any and all help is greatly appreciated.

--
Thanks,
0
Rajkumar_G
Asked:
Rajkumar_G
1 Solution
 
vippxCommented:
Put a xtw.flush() wherever u need the XMLTextWriter to flush the generated XML to the memory stream.
0
 
tzxie2000Commented:
put xtw.flush() before xtw.close()
using ms before xtw.close()
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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