private void SaveXml() ... { XmlDocument doc = new XmlDocument(); string path = Setting.Instance.QuestionXmlFile; doc.Load(path); XmlNodeList nodelist = doc.SelectNodes("//Questionnair/Categorys/Category/Quesition"); AdvisorWebServiceSoapClient service = new AdvisorWebServiceSoapClient(); String version = Function.ReadNodeText(doc.SelectSingleNode("//Questionnair/@Version")); String answer = service.GetAnwsers(_accountId, version); string[] temp = answer.Split(';'); int[] result = new int[20]; for (int i = 0; i < temp.Length - 1; i++) ...{ result[i] = Convert.ToInt32(temp[i].Split(':')[1]); } //问题答案的保存到xml 问题答案的保存到xml#region 问题答案的保存到xml for (int i = 0; i < nodelist.Count; i++) ...{ XmlNode item = nodelist[i]; foreach (XmlNode node in item.SelectNodes("Option")) ...{ if (node.Attributes["Value"].InnerText == result[i].ToString()) ...{ XmlAttribute att = doc.CreateAttribute("Selected"); att.Value = "true"; node.Attributes.Append(att); break; } } } #endregion //分类结果保存到xml 分类结果保存到xml#region 分类结果保存到xml XmlNodeList risk_score = doc.SelectNodes("//Questionnair/Categorys/Category/Results"); for (int i = 0; i < risk_score.Count; i++) ...{ XmlNode scoreresult = risk_score[i]; foreach (XmlNode categoryrisk in scoreresult.SelectNodes("Result")) ...{ int minsoc = Convert.ToInt32(categoryrisk.Attributes["MinScore"].InnerText); int maxsoc = Convert.ToInt32(categoryrisk.Attributes["MaxScore"].InnerText); if (Category[i] >= minsoc && Category[i] <= maxsoc) ...{ XmlAttribute att = doc.CreateAttribute("Selected"); att.Value = "true"; categoryrisk.Attributes.Append(att); break; } } } #endregion //综合类型保存到xml 综合类型保存到xml#region 综合类型保存到xml XmlNodeList riskresult = doc.SelectNodes("//Questionnair/Risks/Risk"); for (int i = 0; i < riskresult.Count; i++) ...{ XmlNode item = riskresult[i]; if (RiskType == item.Attributes["Text"].InnerText) ...{ XmlAttribute att = doc.CreateAttribute("Selected"); att.Value = "true"; item.Attributes.Append(att); XmlElement newnode = doc.CreateElement("Custom"); XmlNode node1 = doc.CreateNode(XmlNodeType.Element, "Stock", ""); node1.InnerText = "股票"; XmlAttribute att1 = doc.CreateAttribute("Percent"); att1.Value = Stock_Customer.ToString(); node1.Attributes.Append(att1); XmlNode node2 = doc.CreateNode(XmlNodeType.Element, "Bond", ""); node2.InnerText = "债券"; XmlAttribute att2 = doc.CreateAttribute("Percent"); att2.Value = Bond_Customer.ToString(); node2.Attributes.Append(att2); XmlNode node3 = doc.CreateNode(XmlNodeType.Element, "Cash", ""); node3.InnerText = "现金"; XmlAttribute att3 = doc.CreateAttribute("Percent"); att3.Value = Cash_Customer.ToString(); node3.Attributes.Append(att3); XmlNode node4 = doc.CreateNode(XmlNodeType.Element, "Other", ""); node4.InnerText = "其他"; XmlAttribute att4 = doc.CreateAttribute("Percent"); att4.Value = Other_Customer.ToString(); node4.Attributes.Append(att4); newnode.AppendChild(node1); newnode.AppendChild(node2); newnode.AppendChild(node3); newnode.AppendChild(node4); item.AppendChild(newnode); break; } } #endregion String output = Setting.Instance.TempDirectory + "result.xml"; doc.Save(output); }