472,146 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

"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 34899
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
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.