Tuesday, 10 September 2013

Export SQL Server CE database file to XML without whitespaces?

Export SQL Server CE database file to XML without whitespaces?

I am trying to export a SQL Server CE database file (.sdf) to XML output
file.
Currently I do this using code below:
SqlCeConnection mConnection = new SqlCeConnection("Data
Source='DataBase.sdf';");
SqlCeCommand mCommand = new SqlCeCommand("SELECT * FROM item", mConnection);
SqlCeDataAdapter da = new SqlCeDataAdapter(mCommand);
DataSet ds = new DataSet();
da.Fill(ds, "item");
StreamWriter xmlDoc = new StreamWriter("Output.xml");
ds.WriteXml(xmlDoc);
xmlDoc.Close();
The problem that I have now is that I receive output in following format:
<NewDataSet>
<item>
<Index>AS31122</Index>
<Owner />
<Serial>SN132101</Serial>
<Model />
<Quantity>1</Quantity>=
<Notes />
</item>
.................. // Several more <item></item>
</NewDataSet>
What I really want instead is flat output of tags.. like this (without
whitespaces):
<inventory>
<item><Index>AS31122</Index><Owner></Owner><Serial>SN132101</Serial><Model></Model><Quantity>1</Quantity><Notes></Notes></item>
........... // Several more <item></item>
</inventory>
I am also curious if how I am doing exporting of XML is the most efficient
method and if I can speed it up somehow.

No comments:

Post a Comment