using XMLTextWriter convert the xml tags to MemoryStream

Posted on 2004-09-01
Last Modified: 2010-05-18
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.WriteComment("Data from CSI")
xtw.WriteElementString("LastName", "Dillan")
xtw.WriteElementString("FirstName", "Bob")
xtw.WriteElementString("MiddleInitial", "E")

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.

Question by:Rajkumar_G

Accepted Solution

vippx earned 200 total points
ID: 11952678
Put a xtw.flush() wherever u need the XMLTextWriter to flush the generated XML to the memory stream.

Expert Comment

ID: 12016945
put xtw.flush() before xtw.close()
using ms before xtw.close()

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordlen challenge 3 61
firstChar challenge 13 110
Java Loop 6 49
Definitions and default visual studio colors 5 58
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now