C# 如何使用多个xml模式验证xml文档
xmlns:m=”http://www.MangoDSP.com/mav/wsdl作为本地文件:“ma.wsdl” xmlns:m0=”http://www.MangoDSP.com/schema作为本地文件:“MaTypes.xsd”C# 如何使用多个xml模式验证xml文档,c#,xml,xsd,validation,C#,Xml,Xsd,Validation,xmlns:m=”http://www.MangoDSP.com/mav/wsdl作为本地文件:“ma.wsdl” xmlns:m0=”http://www.MangoDSP.com/schema作为本地文件:“MaTypes.xsd” 我如何验证它。我已经有一段时间没有这样做了(几年了,真的),我再一次在我的Linux笔记本电脑上发布,所以请原谅我的模糊性 private bool isValid; private ArrayList exceptionList; public bool V
我如何验证它。我已经有一段时间没有这样做了(几年了,真的),我再一次在我的Linux笔记本电脑上发布,所以请原谅我的模糊性
private bool isValid;
private ArrayList exceptionList;
public bool Validate()
{
isValid = true;
exceptionList = new ArrayList();
XmlTextReader reader;
XmlSchema schema;
XmlSchemaCollection schemas = new XmlSchemaCollection();
reader = new XmlTextReader( "schema file 1" );
schema = XmlSchema.Read( reader, new ValidationEventHandler( ValidationError ) );
schemas.Add( schema );
reader = new XmlTextReader( "schema file 2" );
schema = XmlSchema.Read( reader, new ValidationEventHandler( ValidationError ) );
schemas.Add( schema );
reader = new XmlTextReader( "validate this file" );
XmlValidatingReader validatingReader;
validatingReader = new XmlValidatingReader( reader );
validatingReader.ValidationEventHandler += new ValidationEventHandler( ValidationError );
validatingReader.Schemas.Add( schemas );
isValid = true;
exceptionList = new ArrayList();
while ( validatingReader.Read() );
return isValid;
}
private void ValidationError( object sender, ValidationEventArgs e )
{
isValid = false;
exceptionList.Add( e.Exception );
}
您还需要执行一些错误处理和资源清理。如何使用单个XML架构验证XML文档?是否要发布XML?发布它,然后选择XML并按Control-K(带有1001010的按钮)。