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

ERROR saving Grid as XML

SCENARIO
=======================================
I have a Grid and I want to save the values on an XML.
Let me say that I am NOT using DataSet to load valus on my grid.

PROBLEM
=======================================
When I am saving a Grid to XML I get the following exception:
"Token StartElement in state Epilog would result in an invalid XML
document"
SOURCE CODE
=======================================
myXmlTextWriter = new XmlTextWriter (aFileName, null);

myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument();

myXmlTextWriter.WriteStartElement("MyRoot");

for (int i=0; i<this.MyDataGrid.Rows.Count; i++)
{
myXmlTextWriter.WriteStartElement("MyTag");

for (int x=0; x<this.MyDataGrid.Columns.Count; x++)
{

myXmlTextWriter.WriteElementString(this.MyDataGrid .Columns[x].HeaderText.Tri
m(), this.MyDataGrid.Rows[i].Cells[x].Text);
}

myXmlTextWriter.WriteEndElement();
myXmlTextWriter.Flush();
}

myXmlTextWriter.WriteEndElement();

myXmlTextWriter.Flush();
myXmlTextWriter.Close();
=======================================

Anybody sees anything wrong ??
Thanks,
Filippo.
Nov 15 '05 #1
3 1516
It seems that I cannot repeat the call
myXmlTextWriter.WriteStartElement("MyTag");
more than once.

So if that is the problem, how can I write an XML as:
<MyRoot>
<MyTag>
<bubu>111</bubu>
<baba>222</baba>
</MyTag>

<MyTag>
<bubu>333</bubu>
<baba>444</baba>
</MyTag>

<MyTag>
<bubu>555</bubu>
<baba>666</baba>
</MyTag>
</MyRoot>

......with multiple "MyTag" tags?

I am currently using an XmlTextWriter, could be this the problem?

Thanks,
Filippo.

"Filippo Pandiani" <pa********@hotmail.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
SCENARIO
=======================================
I have a Grid and I want to save the values on an XML.
Let me say that I am NOT using DataSet to load valus on my grid.

PROBLEM
=======================================
When I am saving a Grid to XML I get the following exception:
"Token StartElement in state Epilog would result in an invalid XML
document"
SOURCE CODE
=======================================
myXmlTextWriter = new XmlTextWriter (aFileName, null);

myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument();

myXmlTextWriter.WriteStartElement("MyRoot");

for (int i=0; i<this.MyDataGrid.Rows.Count; i++)
{
myXmlTextWriter.WriteStartElement("MyTag");

for (int x=0; x<this.MyDataGrid.Columns.Count; x++)
{

myXmlTextWriter.WriteElementString(this.MyDataGrid .Columns[x].HeaderText.Tri m(), this.MyDataGrid.Rows[i].Cells[x].Text);
}

myXmlTextWriter.WriteEndElement();
myXmlTextWriter.Flush();
}

myXmlTextWriter.WriteEndElement();

myXmlTextWriter.Flush();
myXmlTextWriter.Close();
=======================================

Anybody sees anything wrong ??
Thanks,
Filippo.

Nov 15 '05 #2
Filippo Pandiani wrote:
It seems that I cannot repeat the call
myXmlTextWriter.WriteStartElement("MyTag");
more than once.


Whatever the problem is, that's not it.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #3
OK,
I have found the reason why the error was occurring and it was my mistake.

I had an IF statement when I was creating the <MyRoot> node and for one
specific file, the IF statement was not creating the Root. ..something like:
if (filetype !=1)
myXmlTextWriter.WriteStartElement("MyRoot");

Therefore on that specific scenario, I was setting the repeated node "MyTag"
at the root level,
therefore attempting to create an XML as:

<MyTag>
<bubu>111</bubu>
<baba>222</baba>
</MyTag>
<MyTag>
<bubu>333</bubu>
<baba>444</baba>
</MyTag>
<MyTag>
<bubu>555</bubu>
<baba>666</baba>
</MyTag>
....which is invalid cause it has un undefined number of Root nodes called
"MyTag".

My mistake ...or let's call it my BUG !!!

Filippo.
"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Filippo Pandiani wrote:
It seems that I cannot repeat the call
myXmlTextWriter.WriteStartElement("MyTag");
more than once.


Whatever the problem is, that's not it.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)

Nov 15 '05 #4

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

Similar topics

2
by: satish | last post by:
Hi all, I am writing a file by name "input" out, with a small python code below: grid=open('input','w') grid.write(' ') grid.write('/*number_of_zone\n') grid.write(' ') grid.write('2\n')...
4
by: Filippo Pandiani | last post by:
SCENARIO ======================================= I have a Grid and I want to save the values on an XML. Let me say that I am NOT using DataSet to load valus on my grid. PROBLEM...
4
by: wayne dooley | last post by:
This should be easy. I have 2 tables - CUST and SUBS, which have a 1 to many relationship. I created a form to show fields from CUST and a subform to show those in SUBS. The 2 tables are related...
0
by: NCrum | last post by:
I enter a time in a grid either directly like 10:01 or via the Date picker formatted for time the correct time displays in the grid OK but does not save back to the database, todays' date does but...
4
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a...
1
by: Douglas Gage | last post by:
I have two columns Question Answers Q1 Q2 Q3 Q4 Submit
1
by: Nikhil Patel | last post by:
Hi, I bind a grid to a DataView object. I lose the reference to the underlying DataTable and the DataSet in a postback. Here is the code. Page_Load works fine and I am able to see the rows in...
11
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences...
5
by: Steve Marshall | last post by:
Hi all, I am converting an app which used a picturebox to draw graphs etc onto, then saved them to a file. I can certainly draw things onto a picturbox in VB.NET, but how do I save them to a...
0
by: madhu raju | last post by:
iam saving the data into Ms-Access database using Vb.net Application In that application iam using Data grid view to save the data into the database Here in the below code iam saving the name of...
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:
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.