2 u011098955 u011098955 于 2014.05.29 13:21 提问

XML格式的定义是什么意思?做了一个在线考试系统,要求解释XML文件的格式定义,求解

应该先给出xml的格式定义,再讲述生成xml文件的关键代码,例如先创建个builder,再如何创建节点,如何新增节点属性,如何添加节点内容,如何创建子节点或者 是你可以举一个只包含一道选择题,一道填空题和一道编程题的试卷的例子解释xml文件的格式定义。就像oj那样,举个输入数据的例子,文字解释输入数据的格式!

具体XML的代码如下
using DIT.NET.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DIT.NET.Common
{
public class XMLHelper
{
///
/// 根据Page对象,生成XML
///
///
public static void CreatePageXML(Page page,string fileName)
{
//创建DOM对象
XDocument xDoc = new XDocument();
//创建试卷文档的定义
XDeclaration xDec = new XDeclaration("1.0", "utf-8", "yes");
xDoc.Declaration = xDec;
#region 试卷文件的解释与说明
//创建考试根结点(其中包括当前试卷的创建人,创建时间,试卷难度,试卷对应的科目编号)
XElement pageRoot = new XElement("Page");
pageRoot.SetAttributeValue("CreateName", page.CreateName);
pageRoot.SetAttributeValue("CreateTime", page.CreateTime.ToLocalTime().ToString());
pageRoot.SetAttributeValue("LevelID", page.LevelID);
pageRoot.SetAttributeValue("SubjectCode", page.SubjectCode);
xDoc.Add(pageRoot);
#endregion
//关于试题
int total = 0;
#region 选择题
if (page.SelectQues.Count > 0)
{
XElement selectQue = new XElement("SelectQues");
selectQue.SetAttributeValue("Num", page.SelectQues.Count);
for (int i = 0; i < page.SelectQues.Count; i++)
{
total++;
XElement sq = new XElement("SelectQue");
sq.SetAttributeValue("Total", total);
sq.SetAttributeValue("ID", i + 1);
sq.SetElementValue("Score", page.SelectQues[i].Score);
sq.SetElementValue("LevelID", page.SelectQues[i].LevelID);
sq.SetElementValue("SQName", page.SelectQues[i].SQName);
sq.SetElementValue("SQMode", page.SelectQues[i].SQMode);
sq.SetElementValue("Answer", page.SelectQues[i].Answer);
sq.SetElementValue("SQOptionA", page.SelectQues[i].SQOptionA);
sq.SetElementValue("SQOptionB", page.SelectQues[i].SQOptionB);
sq.SetElementValue("SQOptionC", page.SelectQues[i].SQOptionC);
sq.SetElementValue("SQOptionD", page.SelectQues[i].SQOptionD);
sq.SetElementValue("GiveScore", 0);
sq.SetElementValue("IsComment", 0);
sq.SetElementValue("StuAns", string.Empty);
if (page.SelectQues[i].SQOptionE != null)
{
sq.SetElementValue("SQOptionE", page.SelectQues[i].SQOptionE);
}
if (page.SelectQues[i].SQOptionF!=null)
{
sq.SetElementValue("SQOptionF", page.SelectQues[i].SQOptionF);
}
selectQue.Add(sq);
}
pageRoot.Add(selectQue);
}
#endregion
#region 填空题
if (page.BlankQues.Count >= 0)
{
XElement blankQues = new XElement("BlankQues");
blankQues.SetAttributeValue("Num", page.BlankQues.Count);
for (int i = 0; i < page.BlankQues.Count; i++)
{
total++;
XElement b = new XElement("BlankQue");
b.SetAttributeValue("Total", total);
b.SetAttributeValue("ID", i + 1);
b.SetElementValue("Score", page.BlankQues[i].Score);
b.SetElementValue("LevelID", page.BlankQues[i].LevelID);
b.SetElementValue("AnsQName", page.BlankQues[i].AnsQName);
b.SetElementValue("Answer", page.BlankQues[i].Answer);
#region 测试
b.SetElementValue("GiveScore", 0);
b.SetElementValue("IsComment", 0);
b.SetElementValue("StuAns", string.Empty);
#endregion

                blankQues.Add(b);
            }
            pageRoot.Add(blankQues);
        }
        #endregion
        #region 编程题
        //一:编程题
        if (page.ProgramQues.Count > 0)
        {
            XElement programQue = new XElement("ProgramQues");
            programQue.SetAttributeValue("Num", page.ProgramQues.Count);
            for (int i = 0; i < page.ProgramQues.Count; i++)
            {
                total++;
                XElement pq = new XElement("ProgramQue");
                pq.SetAttributeValue("Total", total);
                pq.SetAttributeValue("ID", i + 1);
                pq.SetElementValue("Score", page.ProgramQues[i].Score);
                pq.SetElementValue("LevelID", page.ProgramQues[i].LevelID);
                pq.SetElementValue("ProgramName", page.ProgramQues[i].ProgramName);
                pq.SetElementValue("ExampleAnswer", page.ProgramQues[i].ExampleAnswer);
                pq.SetElementValue("Result", page.ProgramQues[i].Result);

                #region 测试
                pq.SetElementValue("GiveScore", 0);
                pq.SetElementValue("IsComment", 0);
                pq.SetElementValue("StuAns", string.Empty);

                #endregion

                programQue.Add(pq);
            }
            pageRoot.Add(programQue);
        }
        #endregion
        //string temp = Environment.CurrentDirectory;
        //path = Path.Combine(temp.Substring(0, temp.IndexOf("bin")), path);
        string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
        string dir = str.Substring(0, str.IndexOf("bin")) + @"Page\" + page.SubjectCode + @"\";
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        str = str.Substring(0, str.IndexOf("bin")) + @"Page\" + page.SubjectCode + @"\" + fileName;
        xDoc.Save(str);
    }
    /// <summary>
    /// 从XML试卷文件中加载试卷对象
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static Page LoadPageXMLToPage(string path)
    {
        Page page = new Page();
        XDocument doc = XDocument.Load(path);
        #region 解析试卷文件的解释与说明
        //得到,XML试卷文件的解释与说明
        XElement pageRoot = doc.Root;
        page.CreateName = pageRoot.Attribute("CreateName").Value;
        page.CreateTime = DateTime.Parse(pageRoot.Attribute("CreateTime").Value);
        page.LevelID = int.Parse(pageRoot.Attribute("LevelID").Value);
        page.SubjectCode = pageRoot.Attribute("SubjectCode").Value;
        #endregion
        #region 加载编程题
        XElement programQue = pageRoot.Element("ProgramQues");

        IEnumerable<XElement> pqList = programQue.Elements("ProgramQue");
        List<tb_ProgramQueLib> plist = new List<tb_ProgramQueLib>();
        foreach (var item in pqList)
        {
            tb_ProgramQueLib p = new tb_ProgramQueLib();
            p.LevelID = int.Parse(item.Element("LevelID").Value);
            p.Result = item.Element("Result").Value;
            p.Score = float.Parse(item.Element("Score").Value);
            p.ProgramName = item.Element("ProgramName").Value;
            p.ExampleAnswer = item.Element("ExampleAnswer").Value;
            #region 修正
            p.Total = int.Parse(item.Attribute("Total").Value);
            p.ID = int.Parse(item.Attribute("ID").Value);
            #region 测试
            p.GiveScore = double.Parse(item.Element("GiveScore").Value);
            p.IsComment = int.Parse(item.Element("IsComment").Value);
            p.StuAns = item.Element("StuAns").Value;
            #endregion
            #endregion
            plist.Add(p);
        }
        page.ProgramQues = plist;
        #endregion
        #region 加载填空题
        XElement blankQue = pageRoot.Element("BlankQues");
        if (blankQue != null)
        {
            IEnumerable<XElement> blankQues = blankQue.Elements("BlankQue");
            if (blankQues.Count() > 0)
            {
                List<tb_BlankQueLib> blist = new List<tb_BlankQueLib>();
                foreach (var item in blankQues)
                {
                    tb_BlankQueLib b = new tb_BlankQueLib();
                    b.LevelID = int.Parse(item.Element("LevelID").Value);
                    b.Score = float.Parse(item.Element("Score").Value);
                    b.AnsQName = item.Element("AnsQName").Value;
                    b.Answer = item.Element("Answer").Value;


                    b.Total = int.Parse(item.Attribute("Total").Value);
                    b.ID=int.Parse(item.Attribute("ID").Value);
                    b.GiveScore = double.Parse(item.Element("GiveScore").Value);
                    b.StuAns = item.Element("StuAns").Value;
                    b.IsComment = int.Parse(item.Element("IsComment").Value);
                    blist.Add(b);

                }
                page.BlankQues = blist;
            }
        }

        #endregion
        #region 加载选择题
        XElement selectQue = pageRoot.Element("SelectQues");
        if (selectQue != null)
        {
            IEnumerable<XElement> selectQues = selectQue.Elements("SelectQue");
            if (selectQues.Count() > 0)
            {
                List<tb_SelectQueLib> slist = new List<tb_SelectQueLib>();
                foreach (var item in selectQues)
                {
                    tb_SelectQueLib s = new tb_SelectQueLib();
                    s.LevelID = int.Parse(item.Element("LevelID").Value);
                    s.SQName = item.Element("SQName").Value;
                    s.Score = double.Parse(item.Element("Score").Value);
                    s.Answer = item.Element("Answer").Value;
                    s.SQMode = int.Parse(item.Element("SQMode").Value);
                    s.SQOptionA = item.Element("SQOptionA").Value;
                    s.SQOptionB = item.Element("SQOptionB").Value;
                    s.SQOptionC = item.Element("SQOptionC").Value;
                    s.SQOptionD = item.Element("SQOptionD").Value;


                    s.Total = int.Parse(item.Attribute("Total").Value);
                    s.ID = int.Parse(item.Attribute("ID").Value);
                    s.GiveScore = double.Parse(item.Element("GiveScore").Value);
                    s.IsComment = int.Parse(item.Element("IsComment").Value);
                    s.StuAns = item.Element("StuAns").Value;

                    XElement XE=item.Element("SQOptionE");
                    if(XE!=null)
                    {
                        s.SQOptionE = XE.Value;
                    }
                    XElement  XF=item.Element("SQOptionF");
                    if(XF!=null)
                    {
                        s.SQOptionF = XF.Value;
                    }
                    slist.Add(s);
                }
                page.SelectQues = slist;//将所有的选择题,添加到试卷对象
            }

        }



        #endregion
        return page;
    }

    /// <summary>
    /// 直接就返回XML对象类型
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static XDocument GetPageXMLDocument(string path)
    {
        return XDocument.Load(path);
    }

    /// <summary>
    /// 根据Page对象,及学生的答案,生成学生的考卷XML 
    /// </summary>
    /// <param name="page">所对应的Page对象(也就是对应于某一试卷)</param>
    /// <param name="dicStuAns">学生答案</param>
    /// <param name="kaoWuID">教务ID(属于哪一次考试)</param>
    /// <param name="fileName">根据当前学生的学号作为文件名</param>
    public static void CreateStuAnsXML(StuAnsPage stuAnsPage,string fileName)
    {
        if (stuAnsPage.page == null) { return; };
        //创建DOM对象
        XDocument xDoc = new XDocument();
        //创建试卷文档的定义
        XDeclaration xDec = new XDeclaration("1.0", "utf-8", "yes");
        xDoc.Declaration = xDec;
        #region 试卷文件的解释与说明
        //创建考试根结点(其中包括当前试卷的创建人,创建时间,试卷难度,试卷对应的科目编号)
        XElement pageRoot = new XElement("Page");
        pageRoot.SetAttributeValue("CreateName", stuAnsPage.page.CreateName);
        pageRoot.SetAttributeValue("CreateTime", stuAnsPage.page.CreateTime.ToLocalTime().ToString());
        pageRoot.SetAttributeValue("LevelID", stuAnsPage.page.LevelID);
        pageRoot.SetAttributeValue("SubjectCode", stuAnsPage.page.SubjectCode);
        pageRoot.SetAttributeValue("StuNo", stuAnsPage.StuNo);
        pageRoot.SetAttributeValue("KaoWuID", stuAnsPage.KaoWuID);

        pageRoot.SetAttributeValue("IsComment", (stuAnsPage.IsComment==null)?0:stuAnsPage.IsComment);
        xDoc.Add(pageRoot);
        #endregion
        //关于试题
        int total = 0;
        #region 选择题
        if (stuAnsPage.page.SelectQues.Count > 0)
        {
            stuAnsPage.SelScore = 0;
            stuAnsPage.TotalScore -= stuAnsPage.SelScore;
            XElement selectQue = new XElement("SelectQues");
            selectQue.SetAttributeValue("Num", stuAnsPage.page.SelectQues.Count);
            for (int i = 0; i < stuAnsPage.page.SelectQues.Count; i++)
            {
                total++;
                XElement sq = new XElement("SelectQue");

                sq.SetAttributeValue("ID", i + 1);
                sq.SetAttributeValue("Total", total);
                sq.SetElementValue("Score", stuAnsPage.page.SelectQues[i].Score);
                sq.SetElementValue("GiveScore", (stuAnsPage.page.SelectQues[i].GiveScore == null) ? 0 : stuAnsPage.page.SelectQues[i].GiveScore);
                sq.SetElementValue("IsComment", 1);//因为是自动阅卷
                sq.SetElementValue("LevelID", stuAnsPage.page.SelectQues[i].LevelID);
                sq.SetElementValue("SQName", stuAnsPage.page.SelectQues[i].SQName);
                sq.SetElementValue("SQMode", stuAnsPage.page.SelectQues[i].SQMode);
                sq.SetElementValue("Answer", stuAnsPage.page.SelectQues[i].Answer);
                sq.SetElementValue("StuAns", stuAnsPage.page.SelectQues[i].StuAns);
                sq.SetElementValue("SQOptionA", stuAnsPage.page.SelectQues[i].SQOptionA);
                sq.SetElementValue("SQOptionB", stuAnsPage.page.SelectQues[i].SQOptionB);
                sq.SetElementValue("SQOptionC", stuAnsPage.page.SelectQues[i].SQOptionC);
                sq.SetElementValue("SQOptionD", stuAnsPage.page.SelectQues[i].SQOptionD);
                if (stuAnsPage.page.SelectQues[i].SQOptionE != null)
                {
                    sq.SetElementValue("SQOptionE", stuAnsPage.page.SelectQues[i].SQOptionE);
                }
                if (stuAnsPage.page.SelectQues[i].SQOptionF != null)
                {
                    sq.SetElementValue("SQOptionF", stuAnsPage.page.SelectQues[i].SQOptionF);
                }
                #region 如果这里,如果已经阅卷了,就不要再算

                if (stuAnsPage.page.SelectQues[i].StuAns == stuAnsPage.page.SelectQues[i].Answer)
                {
                    stuAnsPage.SelScore += double.Parse(stuAnsPage.page.SelectQues[i].Score.ToString());
                    stuAnsPage.TotalScore += double.Parse(stuAnsPage.page.SelectQues[i].Score.ToString());
                }

                //} 
                #endregion
                selectQue.Add(sq);
            }
            pageRoot.Add(selectQue);
        }
        #endregion
        if (stuAnsPage.IsComment == 0)
        {
            pageRoot.SetAttributeValue("SelScore", (stuAnsPage.TotalScore == null) ? 0 : stuAnsPage.SelScore);
        }
        pageRoot.SetAttributeValue("TotalScore", stuAnsPage.TotalScore);
        #region 填空题
        if (stuAnsPage.page.BlankQues.Count >= 0)
        {
            stuAnsPage.BlanScore = 0;
            stuAnsPage.TotalScore -= stuAnsPage.BlanScore;
            XElement blankQues = new XElement("BlankQues");
            blankQues.SetAttributeValue("Num", stuAnsPage.page.BlankQues.Count);
            for (int i = 0; i < stuAnsPage.page.BlankQues.Count; i++)
            {
                total++;
                XElement b = new XElement("BlankQue");
                b.SetAttributeValue("Total", total);
                b.SetAttributeValue("ID", i + 1);
                b.SetElementValue("Score", stuAnsPage.page.BlankQues[i].Score);
                b.SetElementValue("GiveScore", (stuAnsPage.page.BlankQues[i].GiveScore == null) ? 0 : stuAnsPage.page.BlankQues[i].GiveScore);
                b.SetElementValue("IsComment", (stuAnsPage.page.BlankQues[i].IsComment == null) ? 0 : stuAnsPage.page.BlankQues[i].IsComment);
                b.SetElementValue("LevelID", stuAnsPage.page.BlankQues[i].LevelID);
                b.SetElementValue("AnsQName", stuAnsPage.page.BlankQues[i].AnsQName);
                b.SetElementValue("Answer", stuAnsPage.page.BlankQues[i].Answer);
                b.SetElementValue("StuAns", stuAnsPage.page.BlankQues[i].StuAns);
                stuAnsPage.BlanScore += (stuAnsPage.page.BlankQues[i].GiveScore == null) ? 0 : stuAnsPage.page.BlankQues[i].GiveScore;
                stuAnsPage.TotalScore += (stuAnsPage.page.BlankQues[i].GiveScore == null) ? 0 : stuAnsPage.page.BlankQues[i].GiveScore;
                blankQues.Add(b);
            }
            pageRoot.Add(blankQues);
        }
        #endregion
        #region 编程题
        //一:编程题
        if (stuAnsPage.page.ProgramQues.Count > 0)
        {
            stuAnsPage.ProScore = 0;
            stuAnsPage.TotalScore -= stuAnsPage.ProScore;
            XElement programQue = new XElement("ProgramQues");
            programQue.SetAttributeValue("Num", stuAnsPage.page.ProgramQues.Count);
            for (int i = 0; i < stuAnsPage.page.ProgramQues.Count; i++)
            {
                total++;
                XElement pq = new XElement("ProgramQue");
                pq.SetAttributeValue("Total", total);
                pq.SetAttributeValue("ID", i + 1);
                pq.SetElementValue("Score", stuAnsPage.page.ProgramQues[i].Score);
                pq.SetElementValue("GiveScore", (stuAnsPage.page.ProgramQues[i].GiveScore == null) ? 0 : stuAnsPage.page.ProgramQues[i].GiveScore);
                pq.SetElementValue("IsComment", (stuAnsPage.page.ProgramQues[i].IsComment == null) ? 0 : stuAnsPage.page.ProgramQues[i].IsComment);
                pq.SetElementValue("LevelID", stuAnsPage.page.ProgramQues[i].LevelID);
                pq.SetElementValue("ProgramName", stuAnsPage.page.ProgramQues[i].ProgramName);
                pq.SetElementValue("ExampleAnswer", stuAnsPage.page.ProgramQues[i].ExampleAnswer);
                pq.SetElementValue("Result", stuAnsPage.page.ProgramQues[i].Result);
                pq.SetElementValue("StuAns", stuAnsPage.page.ProgramQues[i].StuAns);
                stuAnsPage.ProScore += (stuAnsPage.page.ProgramQues[i].GiveScore == null) ? 0 : stuAnsPage.page.ProgramQues[i].GiveScore;
                stuAnsPage.TotalScore += (stuAnsPage.page.ProgramQues[i].GiveScore == null) ? 0 : stuAnsPage.page.ProgramQues[i].GiveScore;
                programQue.Add(pq);
            }
            pageRoot.Add(programQue);
        }
        #endregion

        pageRoot.SetAttributeValue("BlanScore", (stuAnsPage.BlanScore == null) ? 0 : stuAnsPage.BlanScore);
        pageRoot.SetAttributeValue("ProScore", (stuAnsPage.ProScore == null) ? 0 : stuAnsPage.ProScore);
        pageRoot.SetAttributeValue("SelScore", (stuAnsPage.TotalScore == null) ? 0 : stuAnsPage.SelScore);
        pageRoot.SetAttributeValue("TotalScore",stuAnsPage.SelScore+stuAnsPage.ProScore+stuAnsPage.BlanScore);
        //string temp = Environment.CurrentDirectory;
        //path = Path.Combine(temp.Substring(0, temp.IndexOf("bin")), path);
        string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
        string dir = str.Substring(0, str.IndexOf("bin")) + @"StuAns\" + stuAnsPage.page.SubjectCode + @"\" + stuAnsPage.KaoWuID + @"\";
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        str =dir + fileName;
        xDoc.Save(str);
    }

    /// <summary>
    /// 加载学生的考卷,成答卷对象(包括试卷,答案,还有分数信息)
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static StuAnsPage LoadXMLToStuAnsPage(string path)
    {
        StuAnsPage sap = new StuAnsPage();//考生的考卷对象(包括试卷+答案+选择题的成绩)
        Page page = new Page();//考生所使用的试卷对象
        if (!File.Exists(path))
        {
            return null;
        }
        XDocument doc = XDocument.Load(path);
        #region 解析试卷文件的解释与说明
        //得到,XML试卷文件的解释与说明
        XElement pageRoot = doc.Root;
        page.CreateName = pageRoot.Attribute("CreateName").Value;
        page.CreateTime = DateTime.Parse(pageRoot.Attribute("CreateTime").Value);
        page.LevelID = int.Parse(pageRoot.Attribute("LevelID").Value);
        page.SubjectCode = pageRoot.Attribute("SubjectCode").Value;
        #endregion
        #region 加载编程题
        XElement programQue = pageRoot.Element("ProgramQues");
        IEnumerable<XElement> pqList = programQue.Elements("ProgramQue");
        List<tb_ProgramQueLib> plist = new List<tb_ProgramQueLib>();
        foreach (var item in pqList)
        {
            //保存学生答案与题号
            int key = int.Parse(item.Attribute("Total").Value);
            tb_ProgramQueLib p = new tb_ProgramQueLib();
            p.ID = int.Parse(item.Attribute("ID").Value);
            p.Total = key;
            p.LevelID = int.Parse(item.Element("LevelID").Value);
            p.Result = item.Element("Result").Value;
            p.Score = double.Parse(item.Element("Score").Value);
            p.GiveScore = double.Parse(item.Element("GiveScore").Value);
            p.IsComment = int.Parse(item.Element("IsComment").Value);
            p.ProgramName = item.Element("ProgramName").Value;
            p.ExampleAnswer = item.Element("ExampleAnswer").Value;
            p.StuAns = item.Element("StuAns").Value;
            plist.Add(p);
        }
        page.ProgramQues = plist;
        #endregion
        #region 加载填空题
        XElement blankQue = pageRoot.Element("BlankQues");
        if (blankQue != null)
        {
            IEnumerable<XElement> blankQues = blankQue.Elements("BlankQue");
            if (blankQues.Count() > 0)
            {
                List<tb_BlankQueLib> blist = new List<tb_BlankQueLib>();
                foreach (var item in blankQues)
                {
                    //保存学生答案与题号
                    int key = int.Parse(item.Attribute("Total").Value);
                    tb_BlankQueLib b = new tb_BlankQueLib();
                    b.ID = int.Parse(item.Attribute("ID").Value);
                    b.Total = key;
                    b.LevelID = int.Parse(item.Element("LevelID").Value);
                    b.Score = double.Parse(item.Element("Score").Value);
                    b.GiveScore = double.Parse(item.Element("GiveScore").Value);
                    b.IsComment = int.Parse(item.Element("IsComment").Value);
                    b.AnsQName = item.Element("AnsQName").Value;
                    b.Answer = item.Element("Answer").Value;
                    b.StuAns = item.Element("StuAns").Value;
                    blist.Add(b);
                }
                page.BlankQues = blist;
            }
        }

        #endregion
        #region 加载选择题
        XElement selectQue = pageRoot.Element("SelectQues");
        if (selectQue != null)
        {
            IEnumerable<XElement> selectQues = selectQue.Elements("SelectQue");
            if (selectQues.Count() > 0)
            {
                List<tb_SelectQueLib> slist = new List<tb_SelectQueLib>();
                foreach (var item in selectQues)
                {
                    //保存学生答案与题号
                    int key = int.Parse(item.Attribute("Total").Value);
                    tb_SelectQueLib s = new tb_SelectQueLib();
                    s.ID = int.Parse(item.Attribute("ID").Value);
                    s.Total = key;
                    s.LevelID = int.Parse(item.Element("LevelID").Value);
                    s.SQName = item.Element("SQName").Value;
                    s.Score = double.Parse(item.Element("Score").Value);
                    s.GiveScore = double.Parse(item.Element("GiveScore").Value);
                    s.IsComment = int.Parse(item.Element("IsComment").Value);
                    s.Answer = item.Element("Answer").Value;
                    s.StuAns = item.Element("StuAns").Value;
                    s.SQMode = int.Parse(item.Element("SQMode").Value);
                    s.SQOptionA = item.Element("SQOptionA").Value;
                    s.SQOptionB = item.Element("SQOptionB").Value;
                    s.SQOptionC = item.Element("SQOptionC").Value;
                    s.SQOptionD = item.Element("SQOptionD").Value;
                    XElement sqloptionX = item.Element("SQOptionE");
                    XElement sqloptionY = item.Element("SQOptionF");
                    if (sqloptionX != null)
                    {
                        s.SQOptionE = item.Element("SQOptionE").Value;
                    }
                    if (sqloptionY != null)
                    {
                        s.SQOptionF = item.Element("SQOptionF").Value;
                    }
                    slist.Add(s);
                }
                page.SelectQues = slist;//将所有的选择题,添加到试卷对象
            }

        }

        #endregion
        sap.StuNo = (pageRoot.Attribute("StuNo") == null) ? "" : pageRoot.Attribute("StuNo").Value;
        sap.KaoWuID = int.Parse(pageRoot.Attribute("KaoWuID").Value);
        sap.SelScore = double.Parse(pageRoot.Attribute("SelScore").Value);
        sap.TotalScore = double.Parse(pageRoot.Attribute("TotalScore").Value);
        sap.BlanScore = double.Parse(pageRoot.Attribute("BlanScore").Value);
        sap.ProScore = double.Parse(pageRoot.Attribute("ProScore").Value);
        sap.IsComment = int.Parse(pageRoot.Attribute("IsComment").Value);

        sap.page = page;
        return sap;// page;
    }

}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!