安排从数据表

时间:2015-05-29 06:10:59

标签: c# xml datatable

我已将DataTable转换为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;

那么,有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

我不确定您的使用案例,但您可以这样做来解决您的情况。

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

您可以找到工作代码here