我需要将DataTable转换为XML字符串 我使用以下内容转换它:
StringWriter sw = new StringWriter();
tblXml.WriteXml(sw, XmlWriteMode.WriteSchema);
string result = sw.ToString();
我正在获取XML字符串,但声明部分未来。
<?xml version="1.0" encoding="utf-8"?>
如何加入?
答案 0 :(得分:1)
使用XmlTextWriter和WriteStartDocument()
。
XmlTextWriter xmlWriter = new XmlTextWriter(outputStream, Encoding.UTF8);
xmlWriter.WriteStartDocument();
tblXml.WriteXml(xmlWriter);
string result = outputStream.ToString();