最近做一问卷网络搜刮一遍 不是错的就是代码很杂乱.折腾了我几天还是不大理解怎么读取 后来翻看了下msdn 大致摸出点基本 代码copy先 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Xml; namespace TempXml ... { public partial class _Default : System.Web.UI.Page ...{ public string XmlPath = HttpContext.Current.Server.MapPath("Questionnaires.xml"); protected void Page_Load(object sender, EventArgs e) ...{ //XmlNode late_twos = root.SelectSingleNode("classlate/adplaces[@place]"); //if (!Page.IsPostBack) //{ XmlDocument xmlDoc = new XmlDocument(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); xmlDoc.Load(XmlPath); XmlElement root = xmlDoc.DocumentElement; int[] score = new int[50]; int count = 0; XmlNode late_score = root.SelectSingleNode("descendant::Section"); for (int i = 0; i < late_score.ChildNodes.Count; i++) ...{ for (int j = 0; j < late_score.ChildNodes[i].ChildNodes.Count; j++) ...{ if (late_score.ChildNodes[i].ChildNodes[j].Name == "Option") ...{ for (int k = 0; k < late_score.ChildNodes[i].ChildNodes[j].ChildNodes.Count; k++) ...{ if (late_score.ChildNodes[i].ChildNodes[j].ChildNodes[k].Name == "Score") ...{ score[count] = int.Parse(late_score.ChildNodes[i].ChildNodes[j].ChildNodes[k].InnerText); count++; } } } } } XmlNode late_two = root.SelectSingleNode("descendant::QuestionsList"); //XmlNodeList xnlist = xmlDoc.DocumentElement.ChildNodes; for (int i = 0; i < late_two.ChildNodes.Count; i++) ...{ string num = late_two.ChildNodes[i].Attributes["QId"].Value; for (int j = 0; j < late_two.ChildNodes[i].ChildNodes.Count; j++) ...{ if (late_two.ChildNodes[i].ChildNodes[j].Attributes.Count < 1) ...{ Response.Write("</br>" + "问题" + num + ": " + late_two.ChildNodes[i].ChildNodes[j].InnerText + "</br>"); } else ...{ if (count > 47) ...{ count = 0; } Response.Write("<input "); if (late_two.ChildNodes[i].ChildNodes[j].Attributes["Val"].Value == "a") ...{ Response.Write("checked='checked'"); } Response.Write(" id='" + i + j + "'"); Response.Write(" name='" + i + "'"); Response.Write(" type='radio' "); Response.Write("value='" + score[count] + "'"); Response.Write("/>"); Response.Write(late_two.ChildNodes[i].ChildNodes[j].Attributes["Val"].Value + late_two.ChildNodes[i].ChildNodes[j].InnerText + "</br>"); count++; } } } //} } }} 下面好是我的xml <!-- edited with XMLSPY v2004 rel. 4 U (http://www.xmlspy.com) by aaa (ORiON) --> <!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) --> < Questionnaires > < Questionnaire Universe ="0" Client ="1" > < QuestionnaireTitle > 1 </ QuestionnaireTitle > < Section > < QuestionSet > < QNum > 1 </ QNum > < QId > 1 </ QId > < Weight > 2 </ Weight > < Option > < Val > a </ Val > < Score > 5 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 2 </ QNum > < QId > 2 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 3 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 3 </ QNum > < QId > 3 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 5 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 4 </ QNum > < QId > 4 </ QId > < Weight > 1 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 5 </ QNum > < QId > 5 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 3 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 6 </ QNum > < QId > 6 </ QId > < Weight > 1 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 3 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 1 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 4 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 7 </ QNum > < QId > 7 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 8 </ QNum > < QId > 8 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 5 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 3 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 2 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 9 </ QNum > < QId > 9 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 10 </ QNum > < QId > 10 </ QId > < Weight > 2 </ Weight > < Option > < Val > a </ Val > < Score > 5 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 11 </ QNum > < QId > 11 </ QId > < Weight > 3 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > < QuestionSet > < QNum > 12 </ QNum > < QId > 12 </ QId > < Weight > 2 </ Weight > < Option > < Val > a </ Val > < Score > 6 </ Score > </ Option > < Option > < Val > b </ Val > < Score > 4 </ Score > </ Option > < Option > < Val > c </ Val > < Score > 2 </ Score > </ Option > < Option > < Val > d </ Val > < Score > 1 </ Score > </ Option > </ QuestionSet > </ Section > < RiskAssessmentResult > < RiskProfileTitle > 4 </ RiskProfileTitle > < RiskScoringTitle > 5 </ RiskScoringTitle > < RiskToleranceTitle > 6 </ RiskToleranceTitle > < AssetMixSummaryTitle > 7 </ AssetMixSummaryTitle > < AssetMixWarningTitle > 8 </ AssetMixWarningTitle > < CustomAssetMixAgreeTitle > 10 </ CustomAssetMixAgreeTitle > < PortfolioBuilderTitle > 9 </ PortfolioBuilderTitle > < PortfolioBuilderAgreeTitle > 11 </ PortfolioBuilderAgreeTitle > < RiskProfile > < UpperScore > 68 </ UpperScore > < ProfileType > 1 </ ProfileType > < PortfolioFund > < FundClassId > F0000004C5 </ FundClassId > < Weight > 15 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001039 </ FundClassId > < Weight > 40 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001038 </ FundClassId > < Weight > 40 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F0000004MI </ FundClassId > < Weight > 5 </ Weight > </ PortfolioFund > < AssetType > < Code > E </ Code > < Percentage > 15 </ Percentage > </ AssetType > < AssetType > < Code > I </ Code > < Percentage > 40 </ Percentage > </ AssetType > < AssetType > < Code > C </ Code > < Percentage > 40 </ Percentage > </ AssetType > < AssetType > < Code > O </ Code > < Percentage > 5 </ Percentage > </ AssetType > </ RiskProfile > < RiskProfile > < UpperScore > 92 </ UpperScore > < ProfileType > 2 </ ProfileType > < PortfolioFund > < FundClassId > F0000004C5 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001030 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001039 </ FundClassId > < Weight > 40 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001038 </ FundClassId > < Weight > 15 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F0000004MI </ FundClassId > < Weight > 5 </ Weight > </ PortfolioFund > < AssetType > < Code > E </ Code > < Percentage > 40 </ Percentage > </ AssetType > < AssetType > < Code > I </ Code > < Percentage > 40 </ Percentage > </ AssetType > < AssetType > < Code > C </ Code > < Percentage > 15 </ Percentage > </ AssetType > < AssetType > < Code > O </ Code > < Percentage > 5 </ Percentage > </ AssetType > </ RiskProfile > < RiskProfile > < UpperScore > 116 </ UpperScore > < ProfileType > 3 </ ProfileType > < PortfolioFund > < FundClassId > F0000004C5 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001036 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001030 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001039 </ FundClassId > < Weight > 25 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001038 </ FundClassId > < Weight > 10 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F0000004MI </ FundClassId > < Weight > 5 </ Weight > </ PortfolioFund > < AssetType > < Code > E </ Code > < Percentage > 60 </ Percentage > </ AssetType > < AssetType > < Code > I </ Code > < Percentage > 25 </ Percentage > </ AssetType > < AssetType > < Code > C </ Code > < Percentage > 10 </ Percentage > </ AssetType > < AssetType > < Code > O </ Code > < Percentage > 5 </ Percentage > </ AssetType > </ RiskProfile > < RiskProfile > < UpperScore > 140 </ UpperScore > < ProfileType > 4 </ ProfileType > < PortfolioFund > < FundClassId > F0000004C5 </ FundClassId > < Weight > 25 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001036 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001030 </ FundClassId > < Weight > 25 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001039 </ FundClassId > < Weight > 15 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001038 </ FundClassId > < Weight > 10 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F0000004MI </ FundClassId > < Weight > 5 </ Weight > </ PortfolioFund > < AssetType > < Code > E </ Code > < Percentage > 70 </ Percentage > </ AssetType > < AssetType > < Code > I </ Code > < Percentage > 15 </ Percentage > </ AssetType > < AssetType > < Code > C </ Code > < Percentage > 10 </ Percentage > </ AssetType > < AssetType > < Code > O </ Code > < Percentage > 5 </ Percentage > </ AssetType > </ RiskProfile > < RiskProfile > < UpperScore > 164 </ UpperScore > < ProfileType > 5 </ ProfileType > < PortfolioFund > < FundClassId > F0000004C5 </ FundClassId > < Weight > 30 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001036 </ FundClassId > < Weight > 20 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001030 </ FundClassId > < Weight > 30 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F000001039 </ FundClassId > < Weight > 15 </ Weight > </ PortfolioFund > < PortfolioFund > < FundClassId > F0000004MI </ FundClassId > < Weight > 5 </ Weight > </ PortfolioFund > < AssetType > < Code > E </ Code > < Percentage > 80 </ Percentage > </ AssetType > < AssetType > < Code > I </ Code > < Percentage > 15 </ Percentage > </ AssetType > < AssetType > < Code > C </ Code > < Percentage > 0 </ Percentage > </ AssetType > < AssetType > < Code > O </ Code > < Percentage > 5 </ Percentage > </ AssetType > </ RiskProfile > </ RiskAssessmentResult > </ Questionnaire > < QuestionsList > < QuestionSetText QId ="1" Language ="zh-CN" > < QuestionText > 在您的可运用投资的资产中,“绝对需要的”长期负担,例如退休金储备或上学基金,所占的比重为多少? </ QuestionText > < AnswerText Val ="a" > 没有 </ AnswerText > < AnswerText Val ="b" > 百分之五十 </ AnswerText > < AnswerText Val ="c" > 百分之七十五 </ AnswerText > < AnswerText Val ="d" > 全部 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="2" Language ="zh-CN" > < QuestionText > 您可以承受一年之内投资金额下跌多少? </ QuestionText > < AnswerText Val ="a" > 可以安然接受短时期的大幅下跌 </ AnswerText > < AnswerText Val ="b" > 可以接受不超于正常的市场波动 </ AnswerText > < AnswerText Val ="c" > 上限为百分之五 </ AnswerText > < AnswerText Val ="d" > 无法接受任何下跌 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="3" Language ="zh-CN" > < QuestionText > 除在第一题中所提到的"绝对需要的"长期负担外,您希望将多少的可运用投资金额作为不时之需的储备? </ QuestionText > < AnswerText Val ="a" > 没有。到时再说。 </ AnswerText > < AnswerText Val ="b" > 一部份 </ AnswerText > < AnswerText Val ="c" > 大部份 </ AnswerText > < AnswerText Val ="d" > 全部 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="4" Language ="zh-CN" > < QuestionText > 您通常多久会去检查您的投资组合? </ QuestionText > < AnswerText Val ="a" > 每周至少一次 </ AnswerText > < AnswerText Val ="b" > 每月一次 </ AnswerText > < AnswerText Val ="c" > 每年一次 </ AnswerText > < AnswerText Val ="d" > 不想花太多时间/不会花任何时间 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="5" Language ="zh-CN" > < QuestionText > 下列哪个选项的形容得最符合您的情况? </ QuestionText > < AnswerText Val ="a" > 您愿意承受高风险以换取最大的利润 </ AnswerText > < AnswerText Val ="b" > 您愿意在合理的风险中取得利润 </ AnswerText > < AnswerText Val ="c" > 您希望在低风险中取得相对合理的利润 </ AnswerText > < AnswerText Val ="d" > 您可以安然接受低利润,并只可以承担非常低的风险 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="6" Language ="zh-CN" > < QuestionText > 请问您将会如何使用投资组合的获利部份? </ QuestionText > < AnswerText Val ="a" > 再寻找金融市场上新的投资机会 </ AnswerText > < AnswerText Val ="b" > 再投资于收益型品种,以获得未来稳定收入 </ AnswerText > < AnswerText Val ="c" > 作为当期收入 </ AnswerText > < AnswerText Val ="d" > a 与 b 皆对 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="7" Language ="zh-CN" > < QuestionText > 您认为长期预期收益(五年期为例)为多少才算满意? </ QuestionText > < AnswerText Val ="a" > 大约每年百分之二十或以上 </ AnswerText > < AnswerText Val ="b" > 平均每年百分之十 </ AnswerText > < AnswerText Val ="c" > 平均每年百分之五 </ AnswerText > < AnswerText Val ="d" > 与通货膨胀率一样 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="8" Language ="zh-CN" > < QuestionText > 在建立您的财富和资产,您的投资期限是多久? </ QuestionText > < AnswerText Val ="a" > 五年以上 </ AnswerText > < AnswerText Val ="b" > 三年到五年 </ AnswerText > < AnswerText Val ="c" > 一年到三年 </ AnswerText > < AnswerText Val ="d" > 一年以内 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="9" Language ="zh-CN" > < QuestionText > 如果您的投资组合在一个星期之内下跌了百分之十,下列哪个选项最符合您的反应? </ QuestionText > < AnswerText Val ="a" > 无太大影响 </ AnswerText > < AnswerText Val ="b" > 觉得有些可惜 </ AnswerText > < AnswerText Val ="c" > 觉得有些气愤 </ AnswerText > < AnswerText Val ="d" > 无法入睡 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="10" Language ="zh-CN" > < QuestionText > 与您周围的人相比,您对投资风险的承受能力如何? </ QuestionText > < AnswerText Val ="a" > 高 </ AnswerText > < AnswerText Val ="b" > 普通 </ AnswerText > < AnswerText Val ="c" > 低 </ AnswerText > < AnswerText Val ="d" > 非常低 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="11" Language ="zh-CN" > < QuestionText > 在过去的投资中,您承受了多大的风险? </ QuestionText > < AnswerText Val ="a" > 很高 </ AnswerText > < AnswerText Val ="b" > 一般 </ AnswerText > < AnswerText Val ="c" > 一些 </ AnswerText > < AnswerText Val ="d" > 几乎没有 </ AnswerText > </ QuestionSetText > < QuestionSetText QId ="12" Language ="zh-CN" > < QuestionText > 在最近,随着您的投资组合的变动,您对风险的承受能力发生什么变化? </ QuestionText > < AnswerText Val ="a" > 趋向较能承受风险 </ AnswerText > < AnswerText Val ="b" > 没有变化 </ AnswerText > < AnswerText Val ="c" > 更多趋向较为保守 </ AnswerText > < AnswerText Val ="d" > 经常趋向较为保守 </ AnswerText > </ QuestionSetText > </ QuestionsList > </ Questionnaires >