public virtual bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler)
        {
            IXmlSchemaInfo schemaInfo;
            XmlSchemaType schemaType = null;
            XmlSchemaElement schemaElement = null;
            XmlSchemaAttribute schemaAttribute = null;
            switch (this.NodeType)
            {
                case XPathNodeType.Root:
                    if (schemas == null)
                    {
                        throw new InvalidOperationException(Res.GetString("XPathDocument_MissingSchemas"));
                    }
                    schemaType = null;
                    break;

                case XPathNodeType.Element:
                    if (schemas == null)
                    {
                        throw new InvalidOperationException(Res.GetString("XPathDocument_MissingSchemas"));
                    }
                    schemaInfo = this.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        schemaType = schemaInfo.SchemaType;
                        schemaElement = schemaInfo.SchemaElement;
                    }
                    if ((schemaType != null) || (schemaElement != null))
                    {
                        break;
                    }
                    throw new InvalidOperationException(Res.GetString("XPathDocument_NotEnoughSchemaInfo", (object[]) null));

                case XPathNodeType.Attribute:
                    if (schemas == null)
                    {
                        throw new InvalidOperationException(Res.GetString("XPathDocument_MissingSchemas"));
                    }
                    schemaInfo = this.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        schemaType = schemaInfo.SchemaType;
                        schemaAttribute = schemaInfo.SchemaAttribute;
                    }
                    if ((schemaType == null) && (schemaAttribute == null))
                    {
                        throw new InvalidOperationException(Res.GetString("XPathDocument_NotEnoughSchemaInfo", (object[]) null));
                    }
                    break;

                default:
                    throw new InvalidOperationException(Res.GetString("XPathDocument_ValidateInvalidNodeType", (object[]) null));
            }
            XmlReader reader = this.CreateReader();
            CheckValidityHelper helper = new CheckValidityHelper(validationEventHandler, reader as XPathNavigatorReader);
            validationEventHandler = new ValidationEventHandler(helper.ValidationCallback);
            XmlReader reader2 = this.GetValidatingReader(reader, schemas, validationEventHandler, schemaType, schemaElement, schemaAttribute);
            while (reader2.Read())
            {
            }
            return helper.IsValid;
        }
示例#2
0
        public virtual bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler validationEventHandler) {
            IXmlSchemaInfo schemaInfo;
            XmlSchemaType schemaType = null;
            XmlSchemaElement schemaElement = null;
            XmlSchemaAttribute schemaAttribute = null;

            switch (NodeType) {
                case XPathNodeType.Root:
                    if (schemas == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XPathDocument_MissingSchemas));
                    }
                    schemaType = null;
                    break;
                case XPathNodeType.Element:
                    if (schemas == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XPathDocument_MissingSchemas)); 
                    }
                    schemaInfo = SchemaInfo;
                    if (schemaInfo != null) {
                        schemaType = schemaInfo.SchemaType;
                        schemaElement = schemaInfo.SchemaElement;
                    }
                    if (schemaType == null
                        && schemaElement == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XPathDocument_NotEnoughSchemaInfo, null));
                    }
                    break;
                case XPathNodeType.Attribute:
                    if (schemas == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XPathDocument_MissingSchemas)); 
                    }
                    schemaInfo = SchemaInfo;
                    if (schemaInfo != null) {
                        schemaType = schemaInfo.SchemaType;
                        schemaAttribute = schemaInfo.SchemaAttribute;
                    }
                    if (schemaType == null
                        && schemaAttribute == null) {
                        throw new InvalidOperationException(Res.GetString(Res.XPathDocument_NotEnoughSchemaInfo, null));
                    }
                    break;
                default:
                    throw new InvalidOperationException(Res.GetString(Res.XPathDocument_ValidateInvalidNodeType, null));

            }
           
            Debug.Assert( schemaType != null  || this.NodeType == XPathNodeType.Root, "schemaType != null  || this.NodeType == XPathNodeType.Root" );

            XmlReader reader = CreateReader();

            CheckValidityHelper validityTracker = new CheckValidityHelper( validationEventHandler, reader as XPathNavigatorReader );
            validationEventHandler = new ValidationEventHandler( validityTracker.ValidationCallback );
            XmlReader validatingReader = GetValidatingReader( reader, schemas, validationEventHandler, schemaType, schemaElement, schemaAttribute );

            while( validatingReader.Read() )
                ;

            return validityTracker.IsValid;
        }