Why, oh why, won't my XmlTextWriter write properly to the MemoryStream. Or,
why can't I read the xml back out of the MemoryStream! I can't think of a
thing....
Dim reader As XmlReader
Dim stream As MemoryStream = New MemoryStream()
Dim writer As XmlWriter = New XmlTextWriter(stream, Encoding.UTF8)
writer.WriteStartDocument(True)
writer.WriteStartElement("fooitems")
writer.WriteElementString("foo", "myfoo")
writer.WriteEndElement()
writer.WriteEndDocument()
reader = New XmlTextReader(stream)
writer.Close()
reader.MoveToContent()
reader.ReadOuterXml()
After I run this, I get a 'Root Element is missing' error. I can't see that
anything ever gets into the stream. 2 4088
After you write to the stream and before you read from it, set the
Position back to 0.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 25 Jan 2007 14:26:51 -0800, "Random" <ci*******@hotmail.com>
wrote:
>Why, oh why, won't my XmlTextWriter write properly to the MemoryStream. Or, why can't I read the xml back out of the MemoryStream! I can't think of a thing....
Dim reader As XmlReader
Dim stream As MemoryStream = New MemoryStream() Dim writer As XmlWriter = New XmlTextWriter(stream, Encoding.UTF8)
writer.WriteStartDocument(True) writer.WriteStartElement("fooitems") writer.WriteElementString("foo", "myfoo") writer.WriteEndElement() writer.WriteEndDocument()
reader = New XmlTextReader(stream) writer.Close()
reader.MoveToContent() reader.ReadOuterXml()
After I run this, I get a 'Root Element is missing' error. I can't see that anything ever gets into the stream.
Thanks for the tip. I had been trying different scenarios with that as
well. Turns out I had to make three changes......
'after finishing the document with WriteEndDocument, I had to flush the
content to the stream, then reset the position
writer.Flush()
stream.Position = 0
'then, don't close the writer with Close()
"Samuel R. Neff" <sa********@nomail.comwrote in message
news:vr********************************@4ax.com...
>
After you write to the stream and before you read from it, set the
Position back to 0.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 25 Jan 2007 14:26:51 -0800, "Random" <ci*******@hotmail.com>
wrote:
>>Why, oh why, won't my XmlTextWriter write properly to the MemoryStream. Or, why can't I read the xml back out of the MemoryStream! I can't think of a thing....
Dim reader As XmlReader
Dim stream As MemoryStream = New MemoryStream() Dim writer As XmlWriter = New XmlTextWriter(stream, Encoding.UTF8)
writer.WriteStartDocument(True) writer.WriteStartElement("fooitems") writer.WriteElementString("foo", "myfoo") writer.WriteEndElement() writer.WriteEndDocument()
reader = New XmlTextReader(stream) writer.Close()
reader.MoveToContent() reader.ReadOuterXml()
After I run this, I get a 'Root Element is missing' error. I can't see that anything ever gets into the stream.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris |
last post by:
Hi,
I'm stumped and could use some suggestions. I'm trying
to serialize some data to an XML fragment in string form,
then deserialize it from a string back to an XML
fragment, from which I...
|
by: Steve Gilbey |
last post by:
I have a dataset from which I need to extract certain columns, format
them into xml and output to an xmldocument object.
From reading various posts on similar subjects, I have come up with
the...
|
by: Dave |
last post by:
Hi, I'm trying to create an XML document with XMLTextWriter but I want to store it in memory (not write it to a file like so many examples do). I tried the following but with no luck. Should I not...
|
by: vector |
last post by:
Here is a function more or less exactly as I found it from somewhere
on the internet.
static string BeautifyXML(string sXML)
{
string result = "";
System.IO.MemoryStream ms = new...
|
by: SQLScott |
last post by:
I have the following code that is supposed to use the XMLTextWriter to write
the XML to a MemoryStream:
Dim ms As MemoryStream
ms = New MemoryStream
Dim xtw As New Xml.XmlTextWriter(ms,...
|
by: Josh Newman |
last post by:
I'm using the XMLTextWriter to create an XML document. I do not want the
encoding attribure in the XML file.
Instead of:
<?xml version="1.0" encoding="utf-8"?>
I want:
<?xml version="1.0"?>...
|
by: Gustaf Liljegren |
last post by:
I think I must use MemoryStream, but whenever I search for examples of
MemoryStream, I get lots byte-per-byte reading, buffers and so on. It's
hard to understand and seem overkill for my case...
|
by: Marc Gravell |
last post by:
I want to write a method that will accept a stream as a parameter, and which
will write xml to the stream (based in reality on database results) using
the XmlTextWriter class. However, this insists...
|
by: GaryDean |
last post by:
I'm using an XmlTextWriter and it's various methods such as
WriteElementString, WriteStartElement, WriteEndElement, etc to create an xml
document. When I instantiate the XmlTextWriter to a file......
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |