2015-05-29 57 views
0

我已經將我的DataTable轉換爲XML。安排從數據錶轉換的xml

目前XML輸出是這樣的..

<DocumentElement>\r\n <cardDetails>\r\n <mid>123456789190</mid>\r\n <cardnumber>1234</cardnumber>\r\n <expmonth>01</expmonth>\r\n <expyear>2017</expyear>\r\n <cvv>404</cvv>\r\n <amount>3.54</amount>\r\n <exptime>1/1/2017 11:03:38 AM</exptime>\r\n <responsecode>0000</responsecode>\r\n </cardDetails>\r\n 

我希望我的輸出是這樣的..

<DocumentElement> 
<cardDetails> 
<mid>123456789190</mid>  
<cardnumber>123456789190</cardnumber>  
<expmonth>01</expmonth>  
<expyear>2017</expyear> 
<cvv>404</cvv>  
<amount>3.54</amount>  
<exptime>1/1/2017 11:03:38 AM</exptime>  
<responsecode>0000</responsecode> 
</cardDetails 

這裏是我的代碼

DataTable table = getGenerate.generateCard(mid, passcode, amount, expmonth, expyear, expday, days, hrs, numberOfCards); 

      string xmlString = string.Empty; 
      using (TextWriter writer = new StringWriter()) 
      { 
       table.WriteXml(writer); 
       xml = writer.ToString(); 
      } 
     return xml; 

所以,任何幫助?

+0

'\ r \ N'只是未在你的XML的觀點得到應用的返回碼。看看這裏:http://programmers.stackexchange.com/questions/29075/difference-between-n-and-r-n – Bendy

+0

你試過保存到文件? – jdweng

回答

0

我不確定你的用例,但你可以這樣做來解決你的情況。

xml.Split(new [] {@"\r\n"} , StringSplitOptions.RemoveEmptyEntries) 

你可以找到工作的代碼here

+0

謝謝你,但我怎麼會得到這裏的輸出? – jeramay10

+0

@ jeramay10你可以檢查工作的代碼張貼與答案。 –

+0

的foreach(在s.Split VAR(新的[] {@ 「\ r \ n」 個},StringSplitOptions.RemoveEmptyEntries)) \t \t \t { \t \t \t \t Console.WriteLine(a.Trim()); \t \t \t} 我的意思是,如何在這裏得到返回輸出? – jeramay10