1.xsd介绍
详见: http://blog.sina.com.cn/s/blog_ad0672d60102uy6w.html
2.生成xsd
DataSet dataSet = new DataDet();
// read date from xml file
dataSet.ReadXml(@"xml2.xml", XmlReadMode.ReadSchema);
// .. or set data with code
// save as xsd file
System.IO.StreamWriter writer = new System.IO.StreamWriter("Customers.xsd");
dataSet.WriteXmlSchema(writer);
writer.Close();
// get xsd format contents
string schemaString = dataSet.GetXmlSchema();
// save as xml
dataSet.WriteXml(@"xml2_new.xml", XmlWriteMode.WriteSchema);
3.由xsd生成xml
xsd.exe工具可生成操作的cs类,再有生成的cs类生成xml文件
详见: http://blog.sina.com.cn/s/blog_ad0672d60101g02h.html
4.xsd检验xml
using System.Xml;        // for XmlTextReader and XmlValidatingReader
using System.Xml.Schema; // for XmlSchemaCollection (which is used later)
private static bool isValid = true;      // If a validation error occurs,
                                         // set this flag to false in the
                                         // validation event handler. 
XmlTextReader r = new XmlTextReader("ProductWithXSD.xml");
XmlValidatingReader v = new XmlValidatingReader(r);
v.ValidationType = ValidationType.Schema;
v.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler);
while (v.Read())
{
   // Can add code here to process the content.
}
v.Close();
// Check whether the document is valid or invalid.
if (isValid)
   Console.WriteLine("Document is valid");
else
   Console.WriteLine("Document is invalid");
   
public static void MyValidationEventHandler(object sender, 
                                            ValidationEventArgs args) 
{
   isValid = false;
   Console.WriteLine("Validation event\n" + args.Message);
}
// 另一种方法
XDocument xDoc = XDocument.Parse(xxxxxxx);
string xsdPath = ConfigUtils.GetXsdPath(XsdSchemaIdentifier.HHDataItem);
XmlSchemaSet xss = new XmlSchemaSet();
xss.Add("", xsdPath);
fs.Close();
fs.Dispose();
xDoc.Validate(xss, null);

xsd操作的更多相关文章

  1. 【JAVA - SSM】之SSM入门项目的搭建

    最近学习了一下SSM.SSM是 Spring + SpringMVC + MyBatis 整合框架,非常适合WEB后台开发,也是当前很多人的不二选择.这篇博客带大家来创建一个学习SSM的入门程序,从搭 ...

  2. 手动配置三大框架整合:Spring+Struts2+mybatis

    如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...

  3. 【JavaEE】之SSM入门项目的搭建

    最近学习了一下SSM.SSM是 Spring + SpringMVC + MyBatis 整合框架,非常适合WEB后台开发,也是当前很多人的不二选择.这篇博客带大家来创建一个学习SSM的入门程序,从搭 ...

  4. Spring学习之Spring与Mybatis的两种整合方式

    本机使用IDEA 2020.1.MySql 8.0.19,通过Maven进行构建 环境准备 导入maven依赖包 <dependencies> <dependency> < ...

  5. C#操作Xml:如何定义Xsd文件

    Xml Schema的用途 1. 定义一个Xml文档中都有什么元素 2. 定义一个Xml文档中都会有什么属性 3. 定义某个节点的都有什么样的子节点,可以有多少个子节点,子节点出现的顺序 4. 定义元 ...

  6. c#文件操作

    1.创建文件夹 //using System.IO; Directory.CreateDirectory(%%1);   2.创建文件 //using System.IO; File.Create(% ...

  7. mybatis笔记1 基本的配置和操作

    mybatis比较轻量,适合开发比较小型的或者业务比较复杂的系统: 相对于hibernate来说可以灵活的写sql,更灵活的处理遇到的业务逻辑: 可以说hibernate是pojo实体对db的orm映 ...

  8. Eclipse for Java EE软件操作集锦(二)

    看本文章之前请确保已经了解eclipse建立web工程,如果有疑问请查看本系列文章第一篇 eclipse软件操作集锦(一) 1.我们添加一个servlet 配置一下web.xml测试一下是否能正常显示 ...

  9. spring+redis 集群下的操作

    文章就是记录一下工作当中的用到的点,与测试方法以备用,会不断更新. 配置文件spring-redis.xml: <?xml version="1.0" encoding=&q ...

随机推荐

  1. linux shell 中文件编码查看及转换方法

    参考: http://edyfox.codecarver.org/html/vim_fileencodings_detection.html 一.查看文件编码.     在打开文件的时候输入:set ...

  2. Python 字符串中 startswith()方法

    Python startswith() 方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False.如果参数 beg 和 end 指定值,则在指定范围内检查. str.s ...

  3. 获取Linux服务器基本信息的shell脚本

    测试运行环境: SLES12SP2 #!/bin/bash #系统名称:os_type=$(uname -o | awk '{print " | "$0}') #系统位数:32/6 ...

  4. python筛选特定文件的信息按照格式输出到txt

    最近搞数据库,为了把图片文件的信息导入数据库表中,我开始研究python列出图片文件,其中发现因为IE临时文件里有非常多的不需要的图片,就需要筛选掉一些文件. 最终用python输出了所有需要的图片文 ...

  5. Eclipse实现数据库反向生成实体类(pojo)-------(插件安装和实现步骤的说明)

    一.插件安装 1.下载插件: http://jaist.dl.sourceforge.net/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R2008103 ...

  6. 【BZOJ3240】【UOJ#124】【NOI2013】矩阵游戏

    终于看懂一道题QAQ然而NOI都是这种难度题怎么玩QAQ 原题: 婷婷是个喜欢矩阵的小朋友,有一天她想用电脑生成一个巨大的n行m列的矩阵(你不用担心她如何存储).她生成的这个矩阵满足一个神奇的性质:若 ...

  7. itcast-spring-三大框架整合

    三大框架架构(整合原理) struts整合到spring   hibernate整合到spring 导包 eclipse需要导入   myeclipse不用 单独配置spring容器 单独配置stru ...

  8. url和资源的再理解

    元数据管理系统中, 确实是所有的静态资源都放在WebContent 不在dgs这个主项目中,通过url访问了 下面的这个项目在dgs中

  9. skipper http router 简单试用

    说明: 使用源码编译,注意需要FQ,以及golang版本的问题,新版使用的是go mod 进行依赖管理 环境准备 clone 代码 git clone https://github.com/zalan ...

  10. mysql中 where in 用法详解

    这里分两种情况来介绍 1.in 后面是记录集,如: select  *  from  table  where   uname  in(select  uname  from  user); 2.in ...