|
Post by jamsoft on Feb 5, 2004 1:54:48 GMT -5
Hi to everyone here. If I use DataSet.WriteXml(fileName) I get following error br] An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: Token StartElement in state Epilog would result in an invalid XML document.If I comment the last line of following code (ds.WriteXml(fName) everything is O.K. All data are in dataGrid. If I try to write modified DataSet back to Xml file I get this error. The main part of my code br] public Form1() {
InitializeComponent();
string fName="myFile.xml"; DataSet ds= new DataSet(); DataTable tb; DataRow rw;
ds.ReadXml(fName);
dataGrid1.DataSource=ds; dataGrid1.DataMember="data";
tb=ds.Tables"data"; rw=tb.NewRow(); rw[0]="blablabla"; rw[1]="oooooo"; rw[2]="coucou";
tb.Rows.Add(rw); ds.WriteXml(fName);
} Where is the problem ? Lot of thanks for every answer.... J&M
|
|
|
Post by Dangermouse on Feb 5, 2004 3:27:06 GMT -5
Erm what actual xml are you writing?
|
|
|
Post by jamsoft on Feb 5, 2004 3:51:28 GMT -5
I'm writing Xml of this contents br] <?xml version="1.0" standalone="yes"?>
<dictionary subject="metalurgy">
<title>Metalurgy EN</title>
<data word="coke oven battery" translation="koksarenska baterie" note="" /> <data word="valve" translation="ventil" note="blablabla" /> <data word="refractory" translation="zaruvzdorna" note="" /> <data word="bracing" translation="podpera" note="sloup" /> ..... and so on....
</dictionary>
|
|
|
Post by Dangermouse on Feb 5, 2004 3:53:24 GMT -5
Is that already in the file when you are opening it? I dont fully understand your code.
rw[0]="blablabla"; rw[1]="oooooo"; rw[2]="coucou";
Is that what you are trying to write to the xml file?
And as for using xml for a dictionary, wouldnt a database be much more suited (more functions, faster?)
|
|
|
Post by jamsoft on Feb 5, 2004 4:45:59 GMT -5
No, it's not in the file. I will better describe my code br] (In following code I use ' instead of " because of smileys....) public Form1() {
InitializeComponent();
string fName="myFile.xml";
DataSet ds= new DataSet(); DataTable tb; DataRow rw;
ds.ReadXml(fName); //read xml file to dataset dataGrid1.DataSource=ds; //fill DataGrid with DataSet data dataGrid1.DataMember='data';
tb=ds.Tables['data']; //create reference to the table 'data' included in DataSet rw=tb.NewRow(); //create new row object with style of referenced table in DataSet (it means 3 columns - word, translation, note) rw[0]='blablabla'; //enter some text to the first column ('word') of the new row rw[1]='oooooo'; //enter some text to the second column ('translation') of the new row rw[2]="coucou"; //enter some text to the third column ('note') of the new row tb.Rows.Add(rw); //append created row to the table in DataSet ds.WriteXml(fName); //write modified DataSet back to the xml file } I don't want to use database because an application I write is thought as a small help application with only some entries (about 20).Using database in this easy case (it means obligation to buy distribution licence for database, additional installation, creation of ODBC driver etc.) is not the right solution for me.
|
|