Solved

WriteXML need to be RAW

Posted on 2011-03-08
3
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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