大佬教程收集整理的这篇文章主要介绍了c# – 如何使用xmlschemaset和xmlreader.create对xsd模式验证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@,但那些警告吓到了我.
任何帮助都非常感谢.先感谢您!如果我遗漏任何信息,我会很乐意提供更多信息.
// 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,请注明来意。