473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 35037
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jonathan | last post by:
Hi all: I originally posted this in an HTML forum, but have realized that the solution may (a) require a server-side change or (b) be non-existent. In any case, since the page I'm dealing with is...
0
by: damontimm | last post by:
My setup: Mac OS 10.4.4; mysql 4.x ... everything was installed and working fine for some time. Today, I added drupal to my system and had to create a new database in mysql -- now I am having some...
1
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element...
1
by: Tomas | last post by:
When I try to load my xslt i get an xml exception with the message "Root element is missing". The stylesheet works when I preview it in stylus studio, but apparently not in my application. Any...
2
by: tony | last post by:
XslCompiledTransform xslt = new XslCompiledTransform(); ASCIIEncoding encodeToByteArray = new ASCIIEncoding(); MemoryStream inputStream = new MemoryStream(); MemoryStream outputStream = new...
6
by: active | last post by:
This works with Strict Off But not with Strict On Sometimes I can figure out what is needed by running it and using QuickWatch to see the type required but GetObject("winmgmts:\\" &...
11
by: MC | last post by:
I have a couple of customers who are using a program that deserializes an XML file, and on some files, the program fails to see the content of the file -- treats it as zero length and reports "root...
2
by: Tom Chang | last post by:
Try to read following type of XML file, but only get data back on first node: <log id="1234"> <message type="Action"/> </log> <log id="5678"> <message type="Drama"/> </log> <log id="1357">
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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 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.