我正在读取CSV文件并将其转换为XML格式。将CSV与未知架构转换为XML
public static string ConvertCSVToXML(string filePath)
{
var lines = File.ReadAllLines(filePath);
XElement xml = new XElement("RootElement",
from str in lines
let col = str.Split(',')
select new XElement("Item",
new XElement("Column1", col[0]),
new XElement("Column2", col[1]),
new XElement("Column3", col[2]),
new XElement("Column4", col[3])
)
);
return xml.ToString();
}
在这里,我们知道CSV的标题,因此它的工作原理。 如何在CSV模式未定义时将其转换? 文件包含标题行,但不知道有多少标题和标题标题。
那么,有没有什么关于CSV文件的定义? – grek40
是的。这是一个有效的文件! –
你的意思是[这个有效](https://tools.ietf.org/html/rfc4180)?如*中“没有存在的正式规范”*? – grek40