zoukankan      html  css  js  c++  java
  • xsd操作

    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 " + 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);
  • 相关阅读:
    Android AHandle AMessage
    android java 与C 通过 JNI双向通信
    android 系统给应用的jar
    UE4 unreliable 同步问题
    UE4 difference between servertravel and openlevel(多人游戏的关卡切换)
    UE4 Run On owing Client解析(RPC测试)
    UE4 TSubclassOf VS Native Pointer
    UE4 内容示例网络同步Learn
    UE4 多人FPS VR游戏制作笔记
    UE4 分层材质 Layerd Materials
  • 原文地址:https://www.cnblogs.com/baozhu/p/5064897.html
Copyright © 2011-2022 走看看