假设要统计当前系统中所有的试卷进行分析,试卷是以XML格式存储的,所有这就需要将所有零散的XML文件整合起来,处理成一个完整的XML文件,进行分析,

下面是简单额处理方法:

当前XML文件格式:

 <?xml version="1.0" encoding="GB2312"?>
-<exam><examId>8ddf0e2e-ceba-4400-a20f-cf6f432bc5f5</examId>-<main>-<theme type="多选题" class="多选类">-<question type="多选题" class="多选类" pointType="0" point="2" difficulty="1" episteme="我新建的" questionSortId="bd01b0b4-d161-465d-9347-6e9af5ce639b" questionId="815539cc-3dbc-41a7-867c-153ca1f231b7"><questionsContent>我新建的</questionsContent><contentFile/><selectKey index="A">范德萨范德萨</selectKey><selectKey index="B">的萨芬的萨芬</selectKey><selectKey index="C">地方撒法士飞</selectKey><selectCount>3</selectCount><correctKey>1</correctKey><analyes>范德萨分</analyes><analyesFile/></question></theme></main><updata/></exam>

操作代码,一定要添加引用:using System.Xml.XPath;

     /// <summary>
/// 获取文件夹中的所有XML,并且将所有XMl累加
/// </summary>
/// <returns></returns>
public static XDocument GetXMLMore()
{
string examItemPath = @"C:\Users\Administrator\Desktop\Xml";
//试卷或者考试记录存放路径
string path = "";
DirectoryInfo dir = new DirectoryInfo(examItemPath);
FileInfo[] dirinfo = dir.GetFiles(); //获取文件夹下面的子文件
//定义XML对象
XDocument dsExam = null;
//定义XML节点对象
XElement dsele = null; IEnumerable<XElement> list2 = null;
foreach (FileInfo info in dirinfo) //遍历子文件
{
//拼接循环文件路径
path = examItemPath + "\\" + info.Name.ToString();
//如果当前XML对象为空的话,则说明当前文件是第一次加载,则直接添加到XML对象中去
if (dsExam == null)
{ try
{
dsExam = XDocument.Load(path);
}
catch (Exception)
{ throw;
}
}
//否则当前文件不是第一次加载,则说明XML对象中已经存在了XML数据,所有就不能直接读取,获取当前XML文件的节点,将改节点的文件追加到XML对象中去
else
{
//读取XML文件
dsele = XElement.Load(path);
//查找节点
list2 = dsele.XPathSelectElements("./main");
//追加文件
dsExam.Element("exam").Add(list2);
} }
//返回文件
return dsExam;
}

多XML追加操作的更多相关文章

  1. Python实现XML的操作

    本文从以下两个方面, 用Python实现XML的操作: 一. minidom写入XML示例1 二. minidom写入XML示例2 三. ElementTree写入/修改示例 四. ElementTr ...

  2. VS2012 Unit Test —— 我对IdleTest库动的大手术以及对Xml相关操作进行测试的方式

    [1]我的IdleTest源码地址:http://idletest.codeplex.com/ [2]IdleTest改动说明:2013年10月份在保持原有功能的情况下对其动了较大的手术,首先将基本的 ...

  3. sql server中对xml进行操作

    一.前言 SQL Server 2005 引入了一种称为 XML 的本机数据类型.用户可以创建这样的表,它在关系列之外还有一个或多个 XML 类型的列:此外,还允许带有变量和参数.为了更好地支持 XM ...

  4. 对XML的操作

    对XML的操作主要使用到的语法示例: using System.Xml; private static string XmlMarketingStaff = AppDomain.CurrentDoma ...

  5. Xml通用操作类

    using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...

  6. C# XML流操作简单实例

    这里我们先介绍操作XML文件的两个对象:XmlTextReader和XmlTextWriter打开和读取Xml文件使用到的对象就是XmlTextReader对象.下面的例子打开了与程序在同一路径下的一 ...

  7. SQL Server 2008 对XML 数据类型操作

    原文 http://www.cnblogs.com/qinjian123/p/3240702.html 一.前言 从 SQL Server 2005 开始,就增加了 xml 字段类型,也就是说可以直接 ...

  8. 我来讲讲在c#中怎么进行xml文件操作吧,主要是讲解增删改查!

    我把我写的四种方法代码贴上来吧,照着写没啥问题. 注: <bookstore> <book> <Id>1</Id> <tate>2010-1 ...

  9. 由“Jasperrpeorts 4.1.2升级到5.1.2对flex项目的解析”到AS3 带命名空间的XML的操作

    原文同步至:http://www.waylau.com/from-jasperrpeorts-4-1-2-upgraded-to-5-1-2-parsing-of-flex-projects-to-t ...

随机推荐

  1. ios之"performSelector may cause a leak because its selector is unknown"警告原因及其解决办法

    问题描述 项目中使用到了从字符串创建选择器,编译时发现警告:"performSelector may cause a leak because its selector is unknown ...

  2. Topology的构建

    public class BlackListBolt extends BaseRichBolt{ private static Logger logger = Logger.getLogger(Bla ...

  3. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  4. bug_ _ android.view.WindowManager$BadTokenException: Unable to add window -- token

    ========4       关于android的一个常见错误:Unable to add window --token is not valid android.view.WindowManage ...

  5. C++多态的实现及原理详细解析

    C++多态的实现及原理详细解析 作者: 字体:[增加 减小] 类型:转载   C++的多态性用一句话概括就是:在基类的函数前加上virtual关键字,在派生类中重写该函数,运行时将会根据对象的实际类型 ...

  6. Mybatis where 1=1 和 <where>标签

    <select id="selSampleListByIDX4" resultMap="BaseResultMap" parameterType=&quo ...

  7. C++学习7 构造函数

    当创建一个对象时,往往需要做一些初始化工作,例如对数据成员赋值等.为了解决这个问题,C++提供了构造函数. 构造函数(Constructor)是一种特殊的成员函数,它的名字和类名相同,没有返回值,不需 ...

  8. [ActionScript 3.0] Away3D 官网实例

    /* Dynamic tree generation and placement in a night-time scene Demonstrates: How to create a height ...

  9. Django下载中文名文件:

    Django下载中文名文件: from django.utils.http import urlquote from django.http import HttpResponse content = ...

  10. types.MethodType

    http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object-instance 532down voteac ...