Groups | Blog | Home
all groups > dotnet xml > march 2007 >

dotnet xml : "Root element is missing" xml stream problem


lisa.bogart NO[at]SPAM eds.com
3/8/2007 6:29:27 PM
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)
Rick
3/9/2007 12:00:00 AM
add a "WriteEndDocument() like below.

hth,

Rick


[quoted text, click to view]

**********************
xmlTextWriter.WriteEndDocument()

************************

[quoted text, click to view]

Martin Honnen
3/9/2007 12:00:00 AM
[quoted text, click to view]

Set
objStream.Position = 0
before the Load call.

--

Martin Honnen --- MVP XML
lisa.bogart NO[at]SPAM eds.com
3/9/2007 6:11:57 AM
[quoted text, click to view]

Thanks - this fixed it!
AddThis Social Bookmark Button