private void saveWeaker(string name,List<PotsuWeaker>strongClassifier,List<double>_alpha)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode subjects=null;
if (!File.Exists(@"D:\\weaker.xml"))
{
//Create the xml declaration first
xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null));
//Create the root node and append into doc
subjects = xmlDoc.CreateElement("subjects");
xmlDoc.AppendChild(subjects);
}
else
{
xmlDoc.Load("D:\\weaker.xml");
subjects = xmlDoc.SelectSingleNode("subjects");
}
XmlElement subject = xmlDoc.CreateElement("subject");
subject.SetAttribute("name",name);
subjects.AppendChild(subject);
for (int i = 0; i < strongClassifier.Count; i++)
{
// weaker
XmlElement weaker = xmlDoc.CreateElement("weaker");
subject.AppendChild(weaker);
XmlElement findex = xmlDoc.CreateElement("feature_index");
findex.InnerText = string.Format("{0}", strongClassifier[i].findex);
weaker.AppendChild(findex);
XmlElement thr = xmlDoc.CreateElement("threshold");
thr.InnerText = string.Format("{0}", strongClassifier[i].thr);
weaker.AppendChild(thr);
XmlElement p = xmlDoc.CreateElement("parity");
p.InnerText = string.Format("{0}", strongClassifier[i].p);
weaker.AppendChild(p);
XmlElement alpha = xmlDoc.CreateElement("alpha");
alpha.InnerText = string.Format("{0}", _alpha[i]);
weaker.AppendChild(alpha);
}
xmlDoc.Save("D:\\weaker.xml");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
};
}
C# 写xml文件
最新推荐文章于 2021-05-12 13:37:33 发布