zoukankan      html  css  js  c++  java
  • XmlSchema:采用编码实现

    /*--===------------------------------------------===---
    XmlSchema:采用编码实现
                许明会    2007年12月13日 21:37:23
    --===------------------------------------------===---
    */
    using System;
    using System.Xml;
    using System.Xml.Schema;

    namespace xumh
    {
        
    public class runMyApp
        {
            
    static void Main()
            {
                
    //准备XmlSchema
                XmlSchema schema = new XmlSchema();
                
    //准备复杂类型元素Book
                XmlSchemaElement eleBook = new XmlSchemaElement();
                eleBook.Name 
    = "Book";
                XmlSchemaComplexType type 
    = new XmlSchemaComplexType();
                XmlSchemaSequence seq 
    = new XmlSchemaSequence();
                type.Particle 
    =  seq;
                eleBook.SchemaType 
    = type;
                schema.Items.Add(eleBook);

                
    //添加元素Title
                XmlSchemaElement eleTitle = new XmlSchemaElement();
                eleTitle.Name 
    = "Title";
                eleTitle.SchemaTypeName 
    = new XmlQualifiedName("string",
                    
    "http://www.w3.org/2001/XMLSchema");

                
    //添加元素Publisher
                XmlSchemaElement elePub = new XmlSchemaElement();
                elePub.Name 
    = "Publisher";
                elePub.SchemaTypeName 
    = new XmlQualifiedName("string",
                    
    "http://www.w3.org/2001/XMLSchema");
                
                seq.Items.Add(eleTitle);
                seq.Items.Add(elePub);

                
    //验证可靠性
                schema.Compile(new ValidationEventHandler(ValidationHander));
                System.IO.StreamWriter sw
    = new System.IO.StreamWriter(@".\out.xsd");
                schema.Write(sw.BaseStream);
            }
            
    static void ValidationHander(object sender, ValidationEventArgs e)
            {
                Console.WriteLine(
    "架构验证失败!");
                Console.WriteLine(e.Message);

            }
        };
    }
  • 相关阅读:
    HTML 5 --- 移动端viewport:
    Mac Apache 启动Web工程(webserver):
    java对xml文件做增删改查------摘录
    google code 上传源码
    一段下载文件的源码
    delphi 截取指定符号之间的字符串-随机读取
    从github 读取 绝对地址 ini文件
    使用Delphi读取网络上的文本文件,html文件
    ubuntu下新立得(synaptic)软件包管理器安装
    ubuntu下卸载旧Mysql并安装新Mysql(升级)
  • 原文地址:https://www.cnblogs.com/flaaash/p/994170.html
Copyright © 2011-2022 走看看