Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save XML file from Datagrid

Status
Not open for further replies.

embryo6

Programmer
Jan 19, 2006
2
DE
Hi people,

I'm using a XML file in a datagrid... when I save it, I also would like to add a reference to a STYLE SHEET:

Code:
xmlWri := XmlTextWriter.Create('myFile.xml',Encoding.UTF8);
xmlWri.WriteString('<?xml-stylesheet type="text/xsl" href="myFile.xsl"?>');
xmlWri.Close;
ds.writeXML('myFile.xml',XmlWriteMode.IgnoreSchema);
MessageBox.Show('Data saved','Save',MessageBoxButtons.OK);

But the instruction "writeXML" delete all the contents of the file... in other words, it saves correctly all the data, but it doesn't save the string --> <?xml-stylesheet type="text/xsl" href="myFile.xsl"?>

How can I avoid this problem?
Thanks in advance!
 
What types are xmlWri and ds?

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi, Clive
ds is a Dataset, xmlWri is a XmlTextWriter (System.Xml)

I fill the DataGrid with this code:
Code:
ds := DataSet.Create;
ds.ReadXml('myFile.xml');
DataGridXML.DataSource := ds.Tables[0];
DataGridXML.DataBindings;

Then, with another button, I'm trying to save the modified file. This is the whole procedure:
Code:
  if ds.HasChanges then
  begin
    try
      xmlWri := XmlTextWriter.Create('myFile.xml',Encoding.UTF8);
      xmlWri.WriteString('<?xml-stylesheet type="text/xsl" href="myFile.xsl"?>');
      xmlWri.Close;
      ds.writeXML('myFile.xml',XmlWriteMode.IgnoreSchema);
      MessageBox.Show('Data saved','Save',MessageBoxButtons.OK);
    except
      on NullReferenceException do
      MessageBox.Show('Error',ErrOutput.ToString,MessageBoxButtons.OK);
    end;
  end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top