tags:

views:

224

answers:

3

Hmmmm ...

Although it works in most cases, one column has html data in it. It seems that doing this ...

   StringBuilder xmltarget = new StringBuilder();
   XmlWriter xmlWriter = XmlWriter.Create(xmltarget);
   tableData.WriteXml(xmlWriter);

... doesn't identify where this html or binary data exists and wrap the data in cdata tags as it should ...

Is there something i need to do to ensure the relevant checks are made and a working xml string is produced?

A: 

Are the columns typed in the dataset?

Doobi
Yes ....its a fresh pull direct from sql server using a SqlCommand object.
Wardy
+1  A: 

The datatable, I assume that the column with the html in it is just a string? If so then you're going to have to wrap it with the CData tags yourself. I don't think there is any magic in .Net that will do this for you.

I'd be happy to be proven wrong.

ilivewithian
yeh i've been thinking that.Shame ...
Wardy
I gave up looking in the end, I posted this question all over the net and pretty much everyone had no idea how this could be done with a .Net class, i guess it really can't be done automatically. I did however do a spot of refactoring and the solution is about 30 lines of code for both the server and client code. (i'm streaming the resulting xml to a server where it goes in a database).
Wardy
A: 

Investigate the CreateCDataSection function which is a member of System.Xml.XmlDocument. It's pretty straightforward.

You may have to convert the datatable to an xml document object prior to writing it out.

hawbsl
thats the problem though ... if the datatable contains html data / binary data (more an issue with html though) the call to dataTable.WriteXml(destination) fails so all I have is a datatable unless I decide to call open read on my command.
Wardy
I currently get this error if the html contains a full stop "." ....'.', hexadecimal value 0x00, is an invalid character.
Wardy