473,395 Members | 1,418 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,395 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 35038
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...
0
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 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.