我需要从 XML 文件中删除回车,但我得到的只是一个带有一个框(\r)的 XML 文件。我写了这个:
string sourceFileName = textBox1.Text;
StreamReader sr = new StreamReader(sourceFileName);
String line;
String newLine = null;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
//Regex regex = new Regex(@"(\r\n|\r|\n)+");
newLine = line.Replace("\r\n", String.Empty);
//also tried line.Replace("\n", String.Empty).Replace("\r",String.Empty); , but no use
StreamWriter sw = new StreamWriter(@"C:\Users\manish\Desktop\output.xml");
sw.WriteLine(newLine);
sw.Close();
}
这里可能是什么问题。
编辑:
这是示例:
3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 27 31
30 27 3F 3E 3C 72 6F 6F 74 3E 20 E0 A8 8D E2 80
80 E3 B0 80 E4 8C 80 E4 A4 80 E4 90 80 E3 B8 80
E7 8C 80 E7 8C 80 E5 BC 80 E6 98 80 E6 B0 80 E3
88 80 E7 94 80 E3 8C 80 E5 BC 80 E6 B8 80 E6 88
80 E5 BC 80 E7 94 80 E3 8C 80 E5 BC 80 E6 8C 80
E3 84 80 E3 80 80 E5 BC 80 E7 8C 80 E3 84 80 E3
B0 80 E2 BC 80 E4 8C 80 E4 A4 80 E4 90 80 E3 B8
80 E2 80 80 E0 B4 80 E0 B4 80 0A 20 3C 62 6F 6F
6B 74 69 74 6C 65 3E 3C 21 5B 43 44 41 54 41 5B
5D 5D 3E 3C 2F 62 6F 6F 6B 74 69 74 6C 65 3E 3C
70 61 6E 65 6C 73 3E E0 A8 8D E3 B0 80 E7 80 80
<?xml version='10'?><root> à¨â€€ã°€äŒ€ä¤€ä€ã¸€çŒ€çŒ€å¼€æ˜€æ°€ãˆ€ç”€ãŒ€å¼€æ¸€æˆ€å¼€ç”€ãŒ€å¼€æŒ€ã„€ã€€å¼€çŒ€ã„€ã°€â¼€äŒ€ä¤€ä€ã¸€â€€à´€à´€
<booktitle><![CDATA[]]></booktitle><panels>à¨ã°€ç€€æ„€æ¸€æ”€æ°€â€€ç€æ¤€ç€æ°€æ”€ã´€âœ€äœ€ä”€ä¼€äœ€åˆ€ä„€å€€ä €å¤€â€€åŒ€ä¬€ä¤€ä°€ä°€äˆ€å”€ä¤€ä°€ä€ä”€åˆ€âœ€ã¸€à´€à´€
<questionsAndAnswers>à¨ã°€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€ã°€â„€å¬€äŒ€ä€ä„€å€ä„€å¬€ã°€æˆ€ã¸€ä¤€æ¸€ç€æ”€çˆ€ç€€çˆ€æ”€ç€æ¤€æ¸€æœ€â€€ä´€æ„€ç€€çŒ€ã°€â¼€æˆ€ã¸€å´€å´€ã¸€ã°€â¼€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€à´€à´€
<question><![CDATA[<b>1 Location</b> Why is Arabia's location a good one for trade?]]></question>à¨ã°€æ„€æ¸€çŒ€çœ€æ”€çˆ€â¼€ã¸€à´€à´€
<ansCharCount>350</ansCharCount>à¨ã°€â¼€ç„€ç”€æ”€çŒ€ç€æ¤€æ¼€æ¸€çŒ€ä„€æ¸€æ€ä„€æ¸€çŒ€çœ€æ”€çˆ€çŒ€ã¸€à´€à´€
<questionsAndAnswers>à¨ã°€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€ã°€â„€å¬€äŒ€ä€ä„€å€ä„€å¬€ã°€æˆ€ã¸€ä¤€æ¸€ç€æ”€çˆ€ç€€çˆ€æ”€ç€æ¤€æ¸€æœ€â€€ä´€æ„€ç€€çŒ€ã°€â¼€æˆ€ã¸€å´€å´€ã¸€ã°€â¼€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€à´€à´€
<question><![CDATA[<b>2 Movement</b> Why was the location of Mecca ideal for the spread of ideas?]]></question>à¨ã°€æ„€æ¸€çŒ€çœ€æ”€çˆ€â¼€ã¸€à´€à´€
<ansCharCount>350</ansCharCount>à¨ã°€â¼€ç„€ç”€æ”€çŒ€ç€æ¤€æ¼€æ¸€çŒ€ä„€æ¸€æ€ä„€æ¸€çŒ€çœ€æ”€çˆ€çŒ€ã¸€à´€à´€
</panel>à¨ã°€ç€€æ„€æ¸€æ”€æ°€â€€ç€æ¤€ç€æ°€æ”€ã´€âœ€ä´€æ„€æ¤€æ¸€â€€ä¤€æ€æ”€æ„€âœ€ã¸€à´€à´€
<questionsAndAnswers>à¨ã°€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€ã°€â„€å¬€äŒ€ä€ä„€å€ä„€å¬€å´€å´€ã¸€ã°€â¼€æ €æ”€æ„€æ€æ¤€æ¸€æœ€ã¸€à´€à´€
<question><![CDATA[<b>A Analyzing Primary Sources </b>What kind of teaching does the phrase "the use of the pen†refer to?]]></question>à¨ã°€æ„€æ¸€çŒ€çœ€æ”€çˆ€â¼€ã¸€à´€à´€
<ansCharCount>350</ansCharCount>à¨ã°€â¼€ç„€ç”€æ”€çŒ€ç€æ¤€æ¼€æ¸€çŒ€ä„€æ¸€æ€ä„€æ¸€çŒ€çœ
看起来很吓人..呵呵!!