tags:

views:

56

answers:

1

I am using DataSet.ReadXML and DataSet.WriteXML to read and update an XML file. In some places I have a text column that may contain carriage return, linefeed (
)

When I put 
 in the input file, ReadXML works fine and I get \r\l in the column's value. However when I update with DataSet.WriteXML, the output file appears with a line break wherever I would like there to be 


Is there a way to tell the WriteXML to encode special characters that appear in values?

I have looked at XmlWriter, but don't see anything relevant.

A: 

I pose a question in return; are the text columns encoded in CDATA sections? If so, the following may be of help:

http://stackoverflow.com/questions/1216875/how-to-preserve-newlines-in-cdata-when-generating-xml

If not, making them CDATA should help (from the above link):

Element element = xmldoc.createElement("TestElement");                                    
xmldoc.appendChild(element);                                                              
element.appendChild(xmldoc.createCDATASection("first line\nsecond line\n")); 

Obviously in your case you won't be building strings, but you could try putting the fields you read into to CreateCDATASection method.

Hope this helps.

Mark Avenius
Ok - I tried it with CDATA sections in the input file. This appears to work the same as the example I gave above. It reads fine, but WriteXML converts it back to a line break when writing back the XML.
shindigo