我正在编写一个输出模块以在另一个程序上可视化我的数据。
如果您检查代码,我会将点坐标添加到一个字符串,然后将该字符串作为 TextNode 添加到另一个元素。问题是点数可以超过 500000
有没有更好的方法可以将大量文本写入 xml 或者这样可以吗?
XMLElement points = doc.CreateElement("VTK", "DataArray");
string str = "";
for (int i = 0; i < sim.NumberOfParticles; i++)
{
str += sim.pPosX[i].ToString() + " " + sim.pPosY[i] + " " + sim.pPosZ[i] + "\n"
}
XmlText coordinates = doc.CreateTextNode(str);
points.AppendChild(coordinates);
最佳答案
对于此数据量,请使用 XmlWriter
而不是 XmlDocument
。它的流和资源不再是问题。
关于c# - 需要有关在 C# 中使用 XMLText 的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3338553/