Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用多个xml模式验证xml文档_C#_Xml_Xsd_Validation - Fatal编程技术网

C# 如何使用多个xml模式验证xml文档

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

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 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的按钮)。