需要在C#中使用XMLText的建议

Kay*_*ano 1 c# xml

我正在编写一个输出模块来显示我在另一个程序上的数据.

如果检查代码,我将点坐标添加到字符串,然后将此字符串作为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);
Run Code Online (Sandbox Code Playgroud)

Flo*_*chl 6

对于此数据量,请使用XmlWriter而不是a XmlDocument.流和资源不再是问题.