469,270 Members | 1,108 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

"Root element is missing" xml stream problem

I am getting a "Root element is missing" error when I try to load a
stream into and
XmlDocument. Can anyone help me with what I am doing wrong???
Dim xmlTextWriter As XmlTextWriter = Nothing
Dim objFile As FileStream = Nothing

objStream = New MemoryStream()

xmlTextWriter = New System.Xml.XmlTextWriter(objStream, _
Encoding.GetEncoding("iso8859-1"))

xmlTextWriter.Formatting = System.Xml.Formatting.Indented
xmlTextWriter.WriteStartDocument(True)
xmlTextWriter.WriteComment("This file represents " & _
"data for source system.")
xmlTextWriter.WriteStartElement("requests", Nothing)
xmlTextWriter.WriteEndElement() 'End of Requests element
xmlTextWriter.Flush()

objStream = xmlTextWriter.BaseStream()
Dim objXMLDoc As XmlDocument = New XmlDocument
objXMLDoc.Load(objStream)

Mar 9 '07 #1
3 34663
add a "WriteEndDocument() like below.

hth,

Rick
<li*********@eds.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
>I am getting a "Root element is missing" error when I try to load a
stream into and
XmlDocument. Can anyone help me with what I am doing wrong???
Dim xmlTextWriter As XmlTextWriter = Nothing
Dim objFile As FileStream = Nothing

objStream = New MemoryStream()

xmlTextWriter = New System.Xml.XmlTextWriter(objStream, _
Encoding.GetEncoding("iso8859-1"))

xmlTextWriter.Formatting = System.Xml.Formatting.Indented
xmlTextWriter.WriteStartDocument(True)
xmlTextWriter.WriteComment("This file represents " & _
"data for source system.")
xmlTextWriter.WriteStartElement("requests", Nothing)
xmlTextWriter.WriteEndElement() 'End of Requests element
**********************
xmlTextWriter.WriteEndDocument()

************************
xmlTextWriter.Flush()

objStream = xmlTextWriter.BaseStream()
Dim objXMLDoc As XmlDocument = New XmlDocument
objXMLDoc.Load(objStream)

Mar 9 '07 #2
li*********@eds.com wrote:
I am getting a "Root element is missing" error when I try to load a
stream into and
XmlDocument. Can anyone help me with what I am doing wrong???
objStream = xmlTextWriter.BaseStream()
Dim objXMLDoc As XmlDocument = New XmlDocument
objXMLDoc.Load(objStream)
Set
objStream.Position = 0
before the Load call.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 9 '07 #3
On Mar 9, 7:50 am, Martin Honnen <mahotr...@yahoo.dewrote:
lisa.bog...@eds.com wrote:
I am getting a "Rootelementismissing" error when I try to load a
streaminto and
XmlDocument. Can anyone help me with what I am doing wrong???
objStream = xmlTextWriter.BaseStream()
Dim objXMLDoc As XmlDocument = New XmlDocument
objXMLDoc.Load(objStream)

Set
objStream.Position = 0
before the Load call.

--

Martin Honnen --- MVPXML
http://JavaScript.FAQTs.com/
Thanks - this fixed it!

Mar 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by damontimm | last post: by
2 posts views Thread by Tom Chang | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.