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.

shindigo
  • 1,267
  • 15
  • 29

1 Answers1

0

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

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.

Community
  • 1
  • 1
Mark Avenius
  • 13,679
  • 6
  • 42
  • 50
  • 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 Oct 06 '10 at 14:10