Solved

WriteXML need to be RAW

Posted on 2011-03-08
3
589 Views
Last Modified: 2013-12-17
Hi,

I need to write a DataTable to a XML file.
Using WriteXML works fine but specailchars like ampersand are converted to & ...
How need I change my code to get a raw output & ?

Thanks

Andre
DataSet ds = new DataSet("Employees");
adapter.Fill(ds);
System.IO.FileStream streamWrite = new System.IO.FileStream(xmlFilename, System.IO.FileMode.Create);
DataTable dt = ds.Tables[0];
dt.TableName = "Employee";
dt.WriteXml(streamWrite);
streamWrite.Close();

Open in new window

0
Comment
Question by:andre72
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 500 total points
ID: 35133161
private void WriteXmlToFile(DataSet thisDataSet) {
    if (thisDataSet == null) { return; }
    // Create a file name to write to.
    string filename = "myXmlDoc.xml";
    // Create the FileStream to write with.
    System.IO.FileStream myFileStream = new System.IO.FileStream
       (filename, System.IO.FileMode.Create);
    // Create an XmlTextWriter with the fileStream.
    System.Xml.XmlTextWriter myXmlWriter =
       new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.UTF-16);
    // Write to the file with the WriteXml method.
    thisDataSet.WriteXml(myXmlWriter);  
    myXmlWriter.Close();
 }
0
 

Author Closing Comment

by:andre72
ID: 35133216
Thanks
0
 
LVL 8

Expert Comment

by:SunnyDark
ID: 35133368
As per moderators request, the above source's "source" is from the following MSDN aticle here:
http://msdn.microsoft.com/en-us/library/system.data.dataset.writexml%28v=vs.71%29.aspx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question