C#   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c# – 如何使用xmlschemaset和xmlreader.create对xsd模式验证xml大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的程序中修复警告,显然xmlvalidaTing reader和xmlscheR_731_11845@acollection已经过时了.问题是,我不太确定如何.这是尝试使用涉及xmlscheR_731_11845@aset和xmlreader.create的新模板“模仿”先前的验证函数.我首先声明一个模式,然后使用targeturi字符串设置它,然后在设置验证事件处理程序时将其添加到模式集.我认为我的问题是设置读者和输入流.我知道如何使用XmlvalidaTing reader,但如果我想修复这些警告,那么这不是一个选项.这是代码和尝试.在测试期间,只使用了新的验证xml代码,旧的代码被注释掉了.

// New Validation Xml.
            String xsd_file = filename.SubString(0,filename.Length - 3) + "xsd";
            XmlscheR_731_11845@a xsd = new XmlscheR_731_11845@a();
            xsd.sourceUri = xsd_file;

            XmlscheR_731_11845@aSet ss = new XmlscheR_731_11845@aSet();
            ss.ValidationEventHandler += new ValidationEventHandler(ValidationCallBACk);
            ss.Add(xsd);
            if (ss.Count > 0)
            {
                XmlTextReader r = new XmlTextReader(filename2);
                XmlReaderSetTings setTings = new XmlReaderSetTings();
                setTings.ValidationType = ValidationType.scheR_731_11845@a;
                setTings.scheR_731_11845@as.Add(ss);
                setTings.ValidationEventHandler +=new ValidationEventHandler(ValidationCallBACk);
                XmlReader reader = XmlReader.Create(filename2,setTings);
                while (reader.Read())
                {
                }
                reader.Close();
            }

            // Old Validate XML
            XmlscheR_731_11845@aCollection sc = new XmlscheR_731_11845@aCollection();
            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBACk);
            sc.Add(null,xsd_filE);
            if (sc.Count > 0)
            {
                XmlTextReader r = new XmlTextReader(filename2);
                XmlValidaTingReader v = new XmlValidaTingReader(r);
                v.ValidationType = ValidationType.scheR_731_11845@a;
                v.scheR_731_11845@as.Add(sc);
                v.ValidationEventHandler += new ValidationEventHandler(ValidationCallBACk);
                while (v.Read())
                {
                }
                v.Close();
            }

    private void ValidationCallBACk(object sender,ValidationEventArgs E)
    {
        // if Document Validation Fails
        isvalid = false;
        messageConsole.Text = "INVALID. check message and datagridview table.";
        richTextBox1.Text = "The document is invalid: " + e.message;
    }

不幸的是,当我运行程序并尝试验证无效的xml文档时,它会给出一个如下错误:“未声明’URNLookup’元素.” URNLookup元素是xml文件的根元素.我总是可以回到旧的验证@L_262_13@,但那些警告吓到了我.

任何帮助都非常感谢.先感谢您!如果我遗漏任何信息,我会很乐意提供更多信息.

> tf.rz(.NET 3.5 SP1,Visual studio C#2008)

解决方法

我已经解决了这个问题,它现在又重新开始工作而没有任何警告.
在新验证XML中:

// New Validation Xml.
            String xsd_file = filename.SubString(0,filename.Length - 3) + "xsd";
            XmlscheR_731_11845@a xsd = new XmlscheR_731_11845@a();
            xsd.sourceUri = xsd_file;

            XmlscheR_731_11845@aSet ss = new XmlscheR_731_11845@aSet();
            ss.ValidationEventHandler += new ValidationEventHandler(ValidationCallBACk);
            ss.Add(null,xsd_filE);
            if (ss.Count > 0)
            {
                XmlReaderSetTings setTings = new XmlReaderSetTings();
                setTings.ValidationType = ValidationType.scheR_731_11845@a;
                setTings.scheR_731_11845@as.Add(ss);
                setTings.scheR_731_11845@as.Compile();
                setTings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBACk);
                XmlTextReader r = new XmlTextReader(filename2);
                using (XmlReader reader = XmlReader.Create(r,setTings))
                {
                    while (reader.Read())
                    {
                    }
                }
            }

ss.add已更改为具有命名空间和文件字符串.添加了setTings.scheR_731_11845@as.compile(),并添加了“using(xmlreader reader … …”)的无关紧要的重组.

这页帮助了我很多:http://msdn.microsoft.com/en-us/library/fe6y1sfe(v=vs.80).aspx它现在有效.

大佬总结

以上是大佬教程为你收集整理的c# – 如何使用xmlschemaset和xmlreader.create对xsd模式验证xml全部内容,希望文章能够帮你解决c# – 如何使用xmlschemaset和xmlreader.create对xsd模式验证xml所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。