小编Try*_*ing的帖子

在循环中编写XML c#

我如何写出xml

<?xml version="1.0" encoding="UTF-8"?>
<calibration>
  <ZoomLevel 250>0.0100502512562814</ZoomLevel 250>
  <ZoomLevel 250>0.0100502512562814</ZoomLevel 250>
  ........
</calibration>
Run Code Online (Sandbox Code Playgroud)

我知道如何写出来,但我不能写出一个循环,我需要atm我有写的xml表是

public void XMLWrite(Dictionary<string, double> dict)
{
    //write the dictonary into an xml file
    XmlDocument doc = new XmlDocument();
    XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
    doc.AppendChild(docNode);

    XmlNode productsNode = doc.CreateElement("calibration");
    doc.AppendChild(productsNode);

    foreach (KeyValuePair<string, double> entry in dict)
    {
        XmlNode zoomNode = doc.CreateElement("ZoomLevel");

        XmlAttribute ZoomLevel = doc.CreateAttribute(entry.Key.ToString());
        //XmlElement PixelSize = doc.CreateElement (entry.key = entry.Value.ToString());
        zoomNode.Attributes.Append(ZoomLevel);

        productsNode.AppendChild(zoomNode);
    }
    doc.Save(pathName);
}
Run Code Online (Sandbox Code Playgroud)

c# xml linq

1
推荐指数
1
解决办法
5820
查看次数

标签 统计

c# ×1

linq ×1

xml ×1