简体   繁体   中英

How to encode CR LF in DataSet.WriteXML?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM