473,395 Members | 1,870 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.

The Problem of WriteXml

ad
I test the XmlWrite/XmlRead from MemoryStrem, my codes is:

DataSet ds = Will.DM.ExecuteDataset("Select * from Customer);
MemoryStream msOri = new MemoryStream();
ds.WriteXml(msOri);

DataSet ds2 = new DataSet();
ds2.ReadXml(msOri);

It compiled ok, but when it run fail at the last line: ds.WriteXml(msOri);
Ther error message is
System.Xml.XmlException: Root element is missing.

The msOri is write form ds, why it can't read to ds2?
Nov 17 '05 #1
3 4288
The reason is because the pointer in the stream is at the end of the
stream.

You need to reset the position to the beginning of the stream. Before
the call to ReadXml, do this:

// Set the position in the stream to the beginning.
msOri.Position = 0;

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
I test the XmlWrite/XmlRead from MemoryStrem, my codes is:

DataSet ds = Will.DM.ExecuteDataset("Select * from Customer);
MemoryStream msOri = new MemoryStream();
ds.WriteXml(msOri);

DataSet ds2 = new DataSet();
ds2.ReadXml(msOri);

It compiled ok, but when it run fail at the last line:
ds.WriteXml(msOri);
Ther error message is
System.Xml.XmlException: Root element is missing.

The msOri is write form ds, why it can't read to ds2?

Nov 17 '05 #2
VJ
ds.WriteXml(msOri, XmlWriteMode.WriteSchema);

Schema.. has to be saved.. if you want to read back to a DataSet...

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
I test the XmlWrite/XmlRead from MemoryStrem, my codes is:

DataSet ds = Will.DM.ExecuteDataset("Select * from Customer);
MemoryStream msOri = new MemoryStream();
ds.WriteXml(msOri);
DataSet ds2 = new DataSet();
ds2.ReadXml(msOri);

It compiled ok, but when it run fail at the last line:
ds.WriteXml(msOri);
Ther error message is
System.Xml.XmlException: Root element is missing.

The msOri is write form ds, why it can't read to ds2?

Nov 17 '05 #3
ad
Thanks, You give me a great help!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> ¼¶¼g©ó¶l¥ó·s»D:Oz**************@TK2MSFTNGP09.phx.g bl...
The reason is because the pointer in the stream is at the end of the
stream.

You need to reset the position to the beginning of the stream. Before
the call to ReadXml, do this:

// Set the position in the stream to the beginning.
msOri.Position = 0;

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
I test the XmlWrite/XmlRead from MemoryStrem, my codes is:

DataSet ds = Will.DM.ExecuteDataset("Select * from Customer);
MemoryStream msOri = new MemoryStream();
ds.WriteXml(msOri);

DataSet ds2 = new DataSet();
ds2.ReadXml(msOri);

It compiled ok, but when it run fail at the last line:
ds.WriteXml(msOri);
Ther error message is
System.Xml.XmlException: Root element is missing.

The msOri is write form ds, why it can't read to ds2?


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: DraguVaso | last post by:
Hi, I should use XML to synchronize the data from different (VB.NET) applications, and I was just wondering which Overloads of these functions ( ReadXmlSchema, ReadXml and WriteXml) goes the...
1
by: Rahul Agarwal | last post by:
Hi I am trying to write data back to the client using dataset.WriteXML and I have set the Thread.CurrentThread.CurrentCulture to "no" (norwegian) just before writing the data using WriteXML....
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
1
by: Greg R | last post by:
mydataset.WriteXml(strPath + "/my.xml"); produces this error [ArgumentException: URI formats are not supported. System.IO.Path.GetFullPathInternal(String path) +27...
3
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
1
by: Jacky | last post by:
hello i have to know if the writeXML process is a blocking process. Other mean if i write doc.WriteXML(); int i = 0; Is i = 0 can be executed before doc.WriteXML() method ended???? All this...
4
by: Wes | last post by:
Hello, I have an application using an xml dataset to store app and user settings. The problem I am having is related to writexml. I have a save button on my application that updates the dataset...
2
by: Guoqi Zheng | last post by:
Dear sir, I am trying to create to writeXml to create a xml file every day. The WriteXml method of dataset is very nice and easy to use, however, how can I add the following to my xml file? ...
2
by: Tony Johansson | last post by:
Hello! Assume the following : 1. I create a DataSet with some DataRelation. 2. I then use WriteXml to write the DataSet to an Xml document using DataRelation.Nested = True 3.I then read the...
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: 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
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...
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.