public static XmlReaderSettings GetXmlReaderValidationSettings
        (
            string targetNamespace
            , string xsd
            , ValidationType validationType = ValidationType.Schema
            , XmlSchemaValidationFlags xmlSchemaValidationFlags =
            XmlSchemaValidationFlags.AllowXmlAttributes
            | XmlSchemaValidationFlags.AllowXmlAttributes
            | XmlSchemaValidationFlags.ProcessIdentityConstraints
            | XmlSchemaValidationFlags.ProcessInlineSchema
            | XmlSchemaValidationFlags.ProcessSchemaLocation
            | XmlSchemaValidationFlags.ReportValidationWarnings
            , ValidationEventHandler validationEventHandlerAction = null
        )
        {
            XmlSchemaSet      xmlSchemaSet = GetXmlSchemaSet(targetNamespace, xsd);
            XmlReaderSettings xmlReaderValidationSettings = new XmlReaderSettings();

            xmlReaderValidationSettings.ValidationType  = validationType;
            xmlReaderValidationSettings.ValidationFlags = xmlSchemaValidationFlags;
            xmlReaderValidationSettings.Schemas.Add(xmlSchemaSet);
            if (validationEventHandlerAction != null)
            {
                xmlReaderValidationSettings.ValidationEventHandler += validationEventHandlerAction;
            }
            return(xmlReaderValidationSettings);
        }
        void Initialize(XmlResolver resolver)
        {
            nameTable          = null;
            xmlResolver        = (resolver == null ? CreateDefaultResolver() : resolver);
            lineNumberOffset   = 0;
            linePositionOffset = 0;
            checkCharacters    = true;
            conformanceLevel   = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs        = false;
            ignoreComments   = false;
            dtdProcessing    = DtdProcessing.Prohibit;
            closeInput       = false;

            maxCharactersFromEntities = 0;
            maxCharactersInDocument   = 0;

#if !SILVERLIGHT
            schemas          = null;
            validationType   = ValidationType.None;
            validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
 public XmlSchemaValidator(XmlNameTable nameTable, XmlSchemaSet schemas, IXmlNamespaceResolver namespaceResolver, XmlSchemaValidationFlags validationFlags)
 {
     if (nameTable == null)
     {
         throw new ArgumentNullException("nameTable");
     }
     if (schemas == null)
     {
         throw new ArgumentNullException("schemas");
     }
     if (namespaceResolver == null)
     {
         throw new ArgumentNullException("namespaceResolver");
     }
     this.nameTable = nameTable;
     this.nsResolver = namespaceResolver;
     this.validationFlags = validationFlags;
     if (((validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) != XmlSchemaValidationFlags.None) || ((validationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != XmlSchemaValidationFlags.None))
     {
         this.schemaSet = new XmlSchemaSet(nameTable);
         this.schemaSet.ValidationEventHandler += schemas.GetEventHandler();
         this.schemaSet.CompilationSettings = schemas.CompilationSettings;
         this.schemaSet.XmlResolver = schemas.GetResolver();
         this.schemaSet.Add(schemas);
         this.validatedNamespaces = new Hashtable();
     }
     else
     {
         this.schemaSet = schemas;
     }
     this.Init();
 }
        public void CheckSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsNotSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator     val;
            XmlNamespaceManager    ns      = new XmlNamespaceManager(new NameTable());
            XmlSchemaSet           schemas = new XmlSchemaSet();
            XmlSchemaInfo          info    = new XmlSchemaInfo();
            CValidationEventHolder holder  = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val                         = CreateValidator(schemas, ns, allFlags);
            val.XmlResolver             = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);
            ns.AddNamespace("t", "uri:tempuri");

            val.Initialize();
            val.ValidateElement("root", "", info, "t:type1", null, "uri:tempuri " + Path.Combine(TestData, XSDFILE_TARGET_NAMESPACE), null);

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                _exVerifier.IsExceptionOk(holder.lastException, "Sch_XsiTypeNotFound", new string[] { "uri:tempuri:type1" });
            }

            return;
        }
예제 #5
0
        private void Initialize(XmlResolver resolver)
        {
            _nameTable   = null;
            _xmlResolver = resolver;
            // limit the entity resolving to 10 million character. the caller can still
            // override it to any other value or set it to zero for unlimiting it
            _maxCharactersFromEntities = (long)1e7;

            _lineNumberOffset   = 0;
            _linePositionOffset = 0;
            _checkCharacters    = true;
            _conformanceLevel   = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs        = false;
            _ignoreComments   = false;
            _dtdProcessing    = DtdProcessing.Prohibit;
            _closeInput       = false;

            _maxCharactersInDocument = 0;

            _schemas          = null;
            _validationType   = ValidationType.None;
            _validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            _validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;

            _useAsync = false;

            _isReadOnly      = false;
            IsXmlResolverSet = false;
        }
예제 #6
0
        public void Validate(XObject source, XmlSchemaObject partialValidationType, bool addSchemaInfo)
        {
            this.source        = source;
            this.addSchemaInfo = addSchemaInfo;
            XmlSchemaValidationFlags allowXmlAttributes = XmlSchemaValidationFlags.AllowXmlAttributes;
            XmlNodeType nodeType = source.NodeType;

            switch (nodeType)
            {
            case XmlNodeType.Element:
                goto Label_009B;

            case XmlNodeType.Attribute:
                if (!((XAttribute)source).IsNamespaceDeclaration)
                {
                    if (source.Parent == null)
                    {
                        throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_MissingParent"));
                    }
                    goto Label_009B;
                }
                break;

            case XmlNodeType.Document:
                source = ((XDocument)source).Root;
                if (source == null)
                {
                    throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_MissingRoot"));
                }
                allowXmlAttributes |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                goto Label_009B;
            }
            throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_BadNodeType", new object[] { nodeType }));
Label_009B:
            this.namespaceManager = new XmlNamespaceManager(this.schemas.NameTable);
            this.PushAncestorsAndSelf(source.Parent);
            this.validator = new XmlSchemaValidator(this.schemas.NameTable, this.schemas, this.namespaceManager, allowXmlAttributes);
            this.validator.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallback);
            this.validator.XmlResolver             = null;
            if (partialValidationType != null)
            {
                this.validator.Initialize(partialValidationType);
            }
            else
            {
                this.validator.Initialize();
            }
            if (nodeType == XmlNodeType.Attribute)
            {
                this.ValidateAttribute((XAttribute)source);
            }
            else
            {
                this.ValidateElement((XElement)source);
            }
            this.validator.EndValidation();
        }
예제 #7
0
        public bool Validate(XmlNode nodeToValidate)
        {
            XmlSchemaObject?         partialValidationType = null;
            XmlSchemaValidationFlags validationFlags       = XmlSchemaValidationFlags.AllowXmlAttributes;

            Debug.Assert(nodeToValidate.SchemaInfo != null);

            _startNode = nodeToValidate;
            switch (nodeToValidate.NodeType)
            {
            case XmlNodeType.Document:
                validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                break;

            case XmlNodeType.DocumentFragment:
                break;

            case XmlNodeType.Element:     //Validate children of this element
                IXmlSchemaInfo   schemaInfo    = nodeToValidate.SchemaInfo;
                XmlSchemaElement?schemaElement = schemaInfo.SchemaElement;
                if (schemaElement != null)
                {
                    if (!schemaElement.RefName.IsEmpty)
                    {                                                                                 //If it is element ref,
                        partialValidationType = _schemas.GlobalElements[schemaElement.QualifiedName]; //Get Global element with correct Nillable, Default etc
                    }
                    else
                    {     //local element
                        partialValidationType = schemaElement;
                    }
                    //Verify that if there was xsi:type, the schemaElement returned has the correct type set
                    Debug.Assert(schemaElement.ElementSchemaType == schemaInfo.SchemaType);
                }
                else
                {     //Can be an element that matched xs:any and had xsi:type
                    partialValidationType = schemaInfo.SchemaType;

                    if (partialValidationType == null)
                    {     //Validated against xs:any with pc= lax or skip or undeclared / not validated element
                        if (nodeToValidate.ParentNode !.NodeType == XmlNodeType.Document)
                        {
                            //If this is the documentElement and it has not been validated at all
                            nodeToValidate = nodeToValidate.ParentNode;
                        }
                        else
                        {
                            partialValidationType = FindSchemaInfo((nodeToValidate as XmlElement) !);
                            if (partialValidationType == null)
                            {
                                throw new XmlSchemaValidationException(SR.XmlDocument_NoNodeSchemaInfo, null, nodeToValidate);
                            }
                        }
                    }
                }
                break;
예제 #8
0
    public static void Validate(this XContainer node, XmlSchemaSet schemaSet, XmlSchemaValidationFlags validationFlags, ValidationEventHandler validationEventHandler)
    {
        var settings = new XmlReaderSettings();

        settings.ValidationType   = ValidationType.Schema;
        settings.ValidationFlags |= validationFlags;
        if (validationEventHandler != null)
        {
            settings.ValidationEventHandler += validationEventHandler;
        }
        settings.Schemas = schemaSet;
        node.Validate(settings);
    }
예제 #9
0
        protected XmlSchemaValidator CreateValidator(string xsdFilename, string targetNamespace, XmlSchemaValidationFlags flags)
        {
            string path = xsdFilename;
            XmlSchemaSet schemas = new XmlSchemaSet();
            schemas.XmlResolver = new XmlUrlResolver();

            if (!path.StartsWith("file://") && !path.StartsWith("http://"))
                path = Path.Combine(this.TestData, path);

            schemas.Add(targetNamespace, path);
            schemas.Compile();
            return CreateValidator(schemas, flags);
        }
        /// <summary>Validates the specified <paramref name="element"/> object.</summary>
        /// <param name="element">Source object for validation (must be an element).</param>
        private void Validate(XElement element)
        {
            Debug.Assert(element != null, "element != null");

            XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.AllowXmlAttributes;

            this.PushAncestorsAndSelf(element.Parent);

            validator             = new XmlSchemaValidator(schemas.NameTable, schemas, namespaceManager, validationFlags);
            validator.XmlResolver = null;
            validator.Initialize();
            this.ValidateElement(element);
            validator.EndValidation();
        }
        public XmlSchemaValidatingReader(XmlReader reader, XmlReaderSettings settings)
        {
            XmlSchemaValidatingReader <> f__this = this;
            IXmlNamespaceResolver        xmlNamespaceResolver = reader as IXmlNamespaceResolver;

            if (xmlNamespaceResolver == null)
            {
                xmlNamespaceResolver = new XmlNamespaceManager(reader.NameTable);
            }
            XmlSchemaSet xmlSchemaSet = settings.Schemas;

            if (xmlSchemaSet == null)
            {
                xmlSchemaSet = new XmlSchemaSet();
            }
            this.options = settings.ValidationFlags;
            this.reader  = reader;
            this.v       = new XmlSchemaValidator(reader.NameTable, xmlSchemaSet, xmlNamespaceResolver, this.options);
            if (reader.BaseURI != string.Empty)
            {
                this.v.SourceUri = new Uri(reader.BaseURI);
            }
            this.readerLineInfo = (reader as IXmlLineInfo);
            this.getter         = delegate()
            {
                if (< > f__this.v.CurrentAttributeType != null)
                {
                    return(< > f__this.v.CurrentAttributeType.ParseValue(< > f__this.Value, <> f__this.NameTable, <> f__this));
                }
                return(< > f__this.Value);
            };
            this.xsinfo                  = new XmlSchemaInfo();
            this.v.LineInfoProvider      = this;
            this.v.ValidationEventSender = reader;
            this.nsResolver              = xmlNamespaceResolver;
            this.ValidationEventHandler += delegate(object o, ValidationEventArgs e)
            {
                settings.OnValidationError(o, e);
            };
            if (settings != null && settings.Schemas != null)
            {
                this.v.XmlResolver = settings.Schemas.XmlResolver;
            }
            else
            {
                this.v.XmlResolver = new XmlUrlResolver();
            }
            this.v.Initialize();
        }
 private void CreateValidator(XmlSchemaObject partialValidationType, XmlSchemaValidationFlags validationFlags)
 {
     this.validator = new XmlSchemaValidator(this.nameTable, this.schemas, this.NamespaceResolver, validationFlags);
     this.validator.SourceUri = XmlConvert.ToUri(this.document.BaseURI);
     this.validator.XmlResolver = null;
     this.validator.ValidationEventHandler += this.internalEventHandler;
     this.validator.ValidationEventSender = this;
     if (partialValidationType != null)
     {
         this.validator.Initialize(partialValidationType);
     }
     else
     {
         this.validator.Initialize();
     }
 }
 private void CreateValidator(XmlSchemaObject partialValidationType, XmlSchemaValidationFlags validationFlags)
 {
     this.validator                         = new XmlSchemaValidator(this.nameTable, this.schemas, this.NamespaceResolver, validationFlags);
     this.validator.SourceUri               = XmlConvert.ToUri(this.document.BaseURI);
     this.validator.XmlResolver             = null;
     this.validator.ValidationEventHandler += this.internalEventHandler;
     this.validator.ValidationEventSender   = this;
     if (partialValidationType != null)
     {
         this.validator.Initialize(partialValidationType);
     }
     else
     {
         this.validator.Initialize();
     }
 }
예제 #14
0
 /// <summary>Resets the members of the settings class to their default values.</summary>
 public void Reset()
 {
     this.checkCharacters = true;
     this.closeInput      = false;
     this.conformance     = ConformanceLevel.Document;
     this.ignoreComments  = false;
     this.ignoreProcessingInstructions = false;
     this.ignoreWhitespace             = false;
     this.lineNumberOffset             = 0;
     this.linePositionOffset           = 0;
     this.prohibitDtd = true;
     this.schemas     = null;
     this.schemasNeedsInitialization = true;
     this.validationFlags            = (XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.AllowXmlAttributes);
     this.validationType             = ValidationType.None;
     this.xmlResolver = new XmlUrlResolver();
 }
예제 #15
0
        void Initialize(XmlResolver resolver)
        {
            nameTable = null;
#if !SILVERLIGHT
            if (!EnableLegacyXmlSettings())
            {
                xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                maxCharactersFromEntities = (long)1e7;
            }
            else
#endif
            {
                xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                maxCharactersFromEntities = 0;
            }
            lineNumberOffset   = 0;
            linePositionOffset = 0;
            checkCharacters    = true;
            conformanceLevel   = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs        = false;
            ignoreComments   = false;
            dtdProcessing    = DtdProcessing.Prohibit;
            closeInput       = false;

            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas          = null;
            validationType   = ValidationType.None;
            validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
예제 #16
0
        private void Validate(ValidationEventHandler handler,
                              XmlNode node, XmlSchemaValidationFlags flags)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.NameTable           = NameTable;
            settings.Schemas             = schemas;
            settings.Schemas.XmlResolver = resolver;
            settings.XmlResolver         = resolver;
            settings.ValidationFlags     = flags;
            settings.ValidationType      = ValidationType.Schema;
            XmlReader r = XmlReader.Create(
                new XmlNodeReader(node), settings);

            while (!r.EOF)
            {
                r.Read();
            }
        }
예제 #17
0
 private void Initialize()
 {
     this.nameTable                 = null;
     this.xmlResolver               = this.CreateDefaultResolver();
     this.lineNumberOffset          = 0;
     this.linePositionOffset        = 0;
     this.checkCharacters           = true;
     this.conformanceLevel          = System.Xml.ConformanceLevel.Document;
     this.ignoreWhitespace          = false;
     this.ignorePIs                 = false;
     this.ignoreComments            = false;
     this.dtdProcessing             = System.Xml.DtdProcessing.Prohibit;
     this.closeInput                = false;
     this.maxCharactersFromEntities = 0L;
     this.maxCharactersInDocument   = 0L;
     this.schemas          = null;
     this.validationType   = System.Xml.ValidationType.None;
     this.validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
     this.validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
     this.isReadOnly       = false;
 }
예제 #18
0
//
// Public methods
//
        public void Reset()
        {
            CheckReadOnly("Reset");

            nameTable          = null;
            xmlResolver        = new XmlUrlResolver();
            lineNumberOffset   = 0;
            linePositionOffset = 0;
            checkCharacters    = true;
            conformanceLevel   = ConformanceLevel.Document;

            schemas          = null;
            validationType   = ValidationType.None;
            validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
            ignoreWhitespace = false;
            ignorePIs        = false;
            ignoreComments   = false;
            prohibitDtd      = true;
            closeInput       = false;

            isReadOnly = false;
        }
예제 #19
0
        public bool Validate(XmlNode nodeToValidate)
        {
            XmlSchemaObject          partialValidationType = null;
            XmlSchemaValidationFlags validationFlags       = XmlSchemaValidationFlags.AllowXmlAttributes;

            Debug.Assert(nodeToValidate.SchemaInfo != null);

            _startNode = nodeToValidate;
            switch (nodeToValidate.NodeType)
            {
            case XmlNodeType.Document:
                validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                break;

            case XmlNodeType.DocumentFragment:
                break;

            case XmlNodeType.Element:     //Validate children of this element
                IXmlSchemaInfo   schemaInfo    = nodeToValidate.SchemaInfo;
                XmlSchemaElement schemaElement = schemaInfo.SchemaElement;
                if (schemaElement != null)
                {
                    if (!schemaElement.RefName.IsEmpty)
                    {                                                                                 //If it is element ref,
                        partialValidationType = _schemas.GlobalElements[schemaElement.QualifiedName]; //Get Global element with correct Nillable, Default etc
                    }
                    else
                    {     //local element
                        partialValidationType = schemaElement;
                    }
                    //Verify that if there was xsi:type, the schemaElement returned has the correct type set
                    Debug.Assert(schemaElement.ElementSchemaType == schemaInfo.SchemaType);
                }
                else
                {     //Can be an element that matched xs:any and had xsi:type
                    partialValidationType = schemaInfo.SchemaType;

                    if (partialValidationType == null)
                    {     //Validated against xs:any with pc= lax or skip or undeclared / not validated element
                        if (nodeToValidate.ParentNode.NodeType == XmlNodeType.Document)
                        {
                            //If this is the documentElement and it has not been validated at all
                            nodeToValidate = nodeToValidate.ParentNode;
                        }
                        else
                        {
                            partialValidationType = FindSchemaInfo(nodeToValidate as XmlElement);
                            if (partialValidationType == null)
                            {
                                throw new XmlSchemaValidationException(SR.XmlDocument_NoNodeSchemaInfo, null, nodeToValidate);
                            }
                        }
                    }
                }
                break;

            case XmlNodeType.Attribute:
                if (nodeToValidate.XPNodeType == XPathNodeType.Namespace)
                {
                    goto default;
                }
                partialValidationType = nodeToValidate.SchemaInfo.SchemaAttribute;
                if (partialValidationType == null)
                {     //Validated against xs:anyAttribute with pc = lax or skip / undeclared attribute
                    partialValidationType = FindSchemaInfo(nodeToValidate as XmlAttribute);
                    if (partialValidationType == null)
                    {
                        throw new XmlSchemaValidationException(SR.XmlDocument_NoNodeSchemaInfo, null, nodeToValidate);
                    }
                }
                break;

            default:
                throw new InvalidOperationException(SR.Format(SR.XmlDocument_ValidateInvalidNodeType, null));
            }
            _isValid = true;
            CreateValidator(partialValidationType, validationFlags);
            if (_psviAugmentation)
            {
                if (_schemaInfo == null)
                { //Might have created it during FindSchemaInfo
                    _schemaInfo = new XmlSchemaInfo();
                }
                _attributeSchemaInfo = new XmlSchemaInfo();
            }
            ValidateNode(nodeToValidate);
            _validator.EndValidation();
            return(_isValid);
        }
        public XmlSchemaValidator(XmlNameTable nameTable, XmlSchemaSet schemas, IXmlNamespaceResolver namespaceResolver, XmlSchemaValidationFlags validationFlags) {
            if (nameTable == null) {
                throw new ArgumentNullException("nameTable");
            }
            if (schemas == null) {
                throw new ArgumentNullException("schemas");
            }
            if (namespaceResolver == null) {
                throw new ArgumentNullException("namespaceResolver");
            }
            this.nameTable = nameTable;
            this.nsResolver = namespaceResolver;
            this.validationFlags = validationFlags;


            if ( ((validationFlags & XmlSchemaValidationFlags.ProcessInlineSchema) != 0) || ((validationFlags & XmlSchemaValidationFlags.ProcessSchemaLocation) != 0) ) { //Process schema hints in xml document, hence user's set might change
                this.schemaSet = new XmlSchemaSet(nameTable);
                this.schemaSet.ValidationEventHandler += schemas.GetEventHandler();
                this.schemaSet.CompilationSettings = schemas.CompilationSettings;
                this.schemaSet.XmlResolver = schemas.GetResolver();
                this.schemaSet.Add(schemas);
                validatedNamespaces = new Hashtable();
            }
            else { //Use the same set from the user
                this.schemaSet = schemas;
            }
            Init();
        }
//
// Public methods
//
        public void Reset() {
            CheckReadOnly( "Reset" );

            nameTable = null;
            xmlResolver = new XmlUrlResolver();
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            prohibitDtd = true;
            closeInput = false;

            isReadOnly = false;
        }
예제 #22
0
        // ========== CreateValidator ==========

        protected XmlSchemaValidator CreateValidator(XmlSchemaSet schemas, XmlSchemaValidationFlags flags)
        {
            return(new XmlSchemaValidator(schemas.NameTable, schemas, new XmlNamespaceManager(schemas.NameTable), flags));
        }
예제 #23
0
        private void Initialize(XmlResolver resolver)
        {
            _nameTable = null;
            if (!EnableLegacyXmlSettings())
            {
                _xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                _maxCharactersFromEntities = (long)1e7;
            }
            else
            {
                _xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                _maxCharactersFromEntities = 0;
            }
            _lineNumberOffset = 0;
            _linePositionOffset = 0;
            _checkCharacters = true;
            _conformanceLevel = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs = false;
            _ignoreComments = false;
            _dtdProcessing = DtdProcessing.Prohibit;
            _closeInput = false;

            _maxCharactersInDocument = 0;

            _schemas = null;
            _validationType = ValidationType.None;
            _validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            _validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;

            _useAsync = false;

            _isReadOnly = false;
            IsXmlResolverSet = false;
        }
        void Initialize(XmlResolver resolver) {
            nameTable = null;
            xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersFromEntities = 0;
            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
예제 #25
0
        void Initialize(XmlResolver resolver) {
            nameTable = null;
#if !SILVERLIGHT
            if (!EnableLegacyXmlSettings())
            {
                xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                maxCharactersFromEntities = (long) 1e7;
            }
            else
#endif            
            {
                xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                maxCharactersFromEntities = 0;
            }
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
        public void XmlSchemaValidatorDoesNotEnforceIdentityConstraintsOnDefaultAttributesInSomeCases()
        {
            Initialize();
            string xml = @"<?xml version='1.0'?>
<root xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='idF016.xsd'>
	<uid val='test'/>	<uid/></root>"        ;

            string xsd = @"<?xml version='1.0'?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>
	<xsd:element name='root'>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref='uid' maxOccurs='unbounded'/>
			</xsd:sequence>
		</xsd:complexType>
		<xsd:unique id='foo123' name='uuid'>
			<xsd:selector xpath='.//uid'/>
			<xsd:field xpath='@val'/>
		</xsd:unique>
	</xsd:element>
	<xsd:element name='uid' nillable='true'>
		<xsd:complexType>
			<xsd:attribute name='val' type='xsd:string' default='test'/>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>";

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
            XmlSchemaSet        schemas          = new XmlSchemaSet();

            schemas.Add(null, XmlReader.Create(new StringReader(xsd)));
            schemas.Compile();
            XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                                       XmlSchemaValidationFlags.AllowXmlAttributes;
            XmlSchemaValidator validator = new XmlSchemaValidator(namespaceManager.NameTable, schemas, namespaceManager, validationFlags);

            validator.Initialize();
            using (XmlReader r = XmlReader.Create(new StringReader(xsd)))
            {
                while (r.Read())
                {
                    switch (r.NodeType)
                    {
                    case XmlNodeType.Element:
                        namespaceManager.PushScope();
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                if (r.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                                {
                                    namespaceManager.AddNamespace(r.LocalName, r.Value);
                                }
                            } while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        validator.ValidateElement(r.LocalName, r.NamespaceURI, null, null, null, null, null);
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                if (r.NamespaceURI != "http://www.w3.org/2000/xmlns/")
                                {
                                    validator.ValidateAttribute(r.LocalName, r.NamespaceURI, r.Value, null);
                                }
                            } while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        validator.ValidateEndOfAttributes(null);
                        if (r.IsEmptyElement)
                        {
                            goto case XmlNodeType.EndElement;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        validator.ValidateEndElement(null);
                        namespaceManager.PopScope();
                        break;

                    case XmlNodeType.Text:
                        validator.ValidateText(r.Value);
                        break;

                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.Whitespace:
                        validator.ValidateWhitespace(r.Value);
                        break;

                    default:
                        break;
                    }
                }
                validator.EndValidation();
            }
            XmlReaderSettings rs = new XmlReaderSettings();

            rs.ValidationType = ValidationType.Schema;
            rs.Schemas.Add(null, XmlReader.Create(new StringReader(xsd)));

            using (XmlReader r = XmlReader.Create(new StringReader(xml), rs))
            {
                try
                {
                    while (r.Read())
                    {
                        ;
                    }
                }
                catch (XmlSchemaValidationException e) { _output.WriteLine(e.Message); return; }
            }
            Assert.True(false);
        }
 public static XmlReaderSettings GetXmlReaderValidationSettings
                                     (
                                         string targetNamespace
                                         , string xsd
                                         , ValidationType validationType = ValidationType.Schema
                                         , XmlSchemaValidationFlags xmlSchemaValidationFlags =
                                                                             XmlSchemaValidationFlags.AllowXmlAttributes
                                                                             | XmlSchemaValidationFlags.AllowXmlAttributes
                                                                             | XmlSchemaValidationFlags.ProcessIdentityConstraints
                                                                             | XmlSchemaValidationFlags.ProcessInlineSchema
                                                                             | XmlSchemaValidationFlags.ProcessSchemaLocation
                                                                             | XmlSchemaValidationFlags.ReportValidationWarnings
                                         , ValidationEventHandler validationEventHandlerAction = null
                                     )
 {
     XmlSchemaSet xmlSchemaSet = GetXmlSchemaSet(targetNamespace, xsd);
     XmlReaderSettings xmlReaderValidationSettings = new XmlReaderSettings();
     xmlReaderValidationSettings.ValidationType = validationType;
     xmlReaderValidationSettings.ValidationFlags = xmlSchemaValidationFlags;
     xmlReaderValidationSettings.Schemas.Add(xmlSchemaSet);
     if (validationEventHandlerAction != null)
     {
         xmlReaderValidationSettings.ValidationEventHandler += validationEventHandlerAction;
     }
     return xmlReaderValidationSettings;
 }
예제 #28
0
 public static XmlReaderSettings CreateSettings(XmlSchemaValidationFlags validationFlags, ValidationType validationType)
 {
     return(CreateSettings(false, false, true, false, ConformanceLevel.Auto, DtdProcessing.Parse, null, validationFlags, validationType, null, null));
 }
 private void Initialize()
 {
     this.nameTable = null;
     this.xmlResolver = this.CreateDefaultResolver();
     this.lineNumberOffset = 0;
     this.linePositionOffset = 0;
     this.checkCharacters = true;
     this.conformanceLevel = System.Xml.ConformanceLevel.Document;
     this.ignoreWhitespace = false;
     this.ignorePIs = false;
     this.ignoreComments = false;
     this.dtdProcessing = System.Xml.DtdProcessing.Prohibit;
     this.closeInput = false;
     this.maxCharactersFromEntities = 0L;
     this.maxCharactersInDocument = 0L;
     this.schemas = null;
     this.validationType = System.Xml.ValidationType.None;
     this.validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
     this.validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
     this.isReadOnly = false;
 }
 // Constructors
 public XmlSchemaValidator(System.Xml.XmlNameTable nameTable, XmlSchemaSet schemas, System.Xml.IXmlNamespaceResolver namespaceResolver, XmlSchemaValidationFlags validationFlags)
 {
 }
        public bool Validate(XmlNode nodeToValidate)
        {
            XmlSchemaObject          partialValidationType = null;
            XmlSchemaValidationFlags allowXmlAttributes    = XmlSchemaValidationFlags.AllowXmlAttributes;

            this.startNode = nodeToValidate;
            switch (nodeToValidate.NodeType)
            {
            case XmlNodeType.Element:
            {
                IXmlSchemaInfo   schemaInfo    = nodeToValidate.SchemaInfo;
                XmlSchemaElement schemaElement = schemaInfo.SchemaElement;
                if (schemaElement == null)
                {
                    partialValidationType = schemaInfo.SchemaType;
                    if (partialValidationType == null)
                    {
                        if (nodeToValidate.ParentNode.NodeType != XmlNodeType.Document)
                        {
                            partialValidationType = this.FindSchemaInfo(nodeToValidate as XmlElement);
                            if (partialValidationType == null)
                            {
                                throw new XmlSchemaValidationException("XmlDocument_NoNodeSchemaInfo", null, nodeToValidate);
                            }
                        }
                        else
                        {
                            nodeToValidate = nodeToValidate.ParentNode;
                        }
                    }
                }
                else if (schemaElement.RefName.IsEmpty)
                {
                    partialValidationType = schemaElement;
                }
                else
                {
                    partialValidationType = this.schemas.GlobalElements[schemaElement.QualifiedName];
                }
                goto Label_0110;
            }

            case XmlNodeType.Attribute:
                if (nodeToValidate.XPNodeType != XPathNodeType.Namespace)
                {
                    partialValidationType = nodeToValidate.SchemaInfo.SchemaAttribute;
                    if (partialValidationType == null)
                    {
                        partialValidationType = this.FindSchemaInfo(nodeToValidate as XmlAttribute);
                        if (partialValidationType == null)
                        {
                            throw new XmlSchemaValidationException("XmlDocument_NoNodeSchemaInfo", null, nodeToValidate);
                        }
                    }
                    goto Label_0110;
                }
                break;

            case XmlNodeType.Document:
                allowXmlAttributes |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                goto Label_0110;

            case XmlNodeType.DocumentFragment:
                goto Label_0110;
            }
            throw new InvalidOperationException(Res.GetString("XmlDocument_ValidateInvalidNodeType", (object[])null));
Label_0110:
            this.isValid = true;
            this.CreateValidator(partialValidationType, allowXmlAttributes);
            if (this.psviAugmentation)
            {
                if (this.schemaInfo == null)
                {
                    this.schemaInfo = new XmlSchemaInfo();
                }
                this.attributeSchemaInfo = new XmlSchemaInfo();
            }
            this.ValidateNode(nodeToValidate);
            this.validator.EndValidation();
            return(this.isValid);
        }
예제 #32
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType, XmlSchemaSet schemaSet, ValidationEventHandler onErrorHandler)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, schemaSet, onErrorHandler));
 }
예제 #33
0
        public void CheckNoNamespaceSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val = CreateValidator(schemas, allFlags);
            val.XmlResolver = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE));

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                //XmlExceptionVerifier.IsExceptionOk(holder.lastException);
            }

            return;
        }
예제 #34
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, null, null));
 }
예제 #35
0
 protected XmlSchemaValidator CreateValidator(XmlSchemaSet schemas, IXmlNamespaceResolver nsRes, XmlSchemaValidationFlags flags)
 {
     return(new XmlSchemaValidator(schemas.NameTable, schemas, nsRes, flags));
 }
예제 #36
0
 public static XmlReaderSettings CreateSettings(bool ignoreWhitespace, bool ignoreComments, XmlSchemaValidationFlags validationFlags,
                                                ValidationType validationType)
 {
     return(CreateSettings(ignoreWhitespace, ignoreComments, true, false, ConformanceLevel.Auto, DtdProcessing.Parse, null, validationFlags, validationType, null,
                           null));
 }
예제 #37
0
        protected XmlSchemaValidator CreateValidator(string xsdFilename, string targetNamespace, XmlSchemaValidationFlags flags)
        {
            string       path    = xsdFilename;
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.XmlResolver = new XmlUrlResolver();

            if (!path.StartsWith("file://") && !path.StartsWith("http://"))
            {
                path = Path.Combine(this.TestData, path);
            }

            schemas.Add(targetNamespace, path);
            schemas.Compile();
            return(CreateValidator(schemas, flags));
        }
예제 #38
0
        public void Validate(XObject source, XmlSchemaObject?partialValidationType, bool addSchemaInfo)
        {
            this.source        = source;
            this.addSchemaInfo = addSchemaInfo;
            XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.AllowXmlAttributes;
            XmlNodeType nt = source.NodeType;

            switch (nt)
            {
            case XmlNodeType.Document:
                source = ((XDocument)source).Root !;
                if (source == null)
                {
                    throw new InvalidOperationException(SR.InvalidOperation_MissingRoot);
                }
                validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                break;

            case XmlNodeType.Element:
                break;

            case XmlNodeType.Attribute:
                if (((XAttribute)source).IsNamespaceDeclaration)
                {
                    goto default;
                }
                if (source.Parent == null)
                {
                    throw new InvalidOperationException(SR.InvalidOperation_MissingParent);
                }
                break;

            default:
                throw new InvalidOperationException(SR.Format(SR.InvalidOperation_BadNodeType, nt));
            }
            namespaceManager = new XmlNamespaceManager(schemas.NameTable);
            PushAncestorsAndSelf(source.Parent);
            validator = new XmlSchemaValidator(schemas.NameTable, schemas, namespaceManager, validationFlags);
            validator.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            validator.XmlResolver             = null;
            if (partialValidationType != null)
            {
                validator.Initialize(partialValidationType);
            }
            else
            {
                validator.Initialize();
            }

            IXmlLineInfo orginal = SaveLineInfo(source);

            if (nt == XmlNodeType.Attribute)
            {
                ValidateAttribute((XAttribute)source);
            }
            else
            {
                ValidateElement((XElement)source);
            }
            validator.EndValidation();
            RestoreLineInfo(orginal);
        }
예제 #39
0
        // ========== CreateValidator ==========

        protected XmlSchemaValidator CreateValidator(XmlSchemaSet schemas, XmlSchemaValidationFlags flags)
        {
            return new XmlSchemaValidator(schemas.NameTable, schemas, new XmlNamespaceManager(schemas.NameTable), flags);
        }
예제 #40
0
 protected XmlSchemaValidator CreateValidator(XmlSchemaSet schemas, IXmlNamespaceResolver nsRes, XmlSchemaValidationFlags flags)
 {
     return new XmlSchemaValidator(schemas.NameTable, schemas, nsRes, flags);
 }
예제 #41
0
        public static XmlReaderSettings CreateSettings(bool ignoreWhitespace, bool ignoreComments, bool checkCharacters, bool ignoreProcessingInstructions,
                                                       ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver, XmlSchemaValidationFlags validationFlags, ValidationType validationType,
                                                       XmlSchemaSet schemaSet, ValidationEventHandler onErrorHandler)
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
                CloseInput                   = true,
                IgnoreComments               = ignoreComments,
                IgnoreWhitespace             = ignoreWhitespace,
                CheckCharacters              = checkCharacters,
                IgnoreProcessingInstructions = ignoreProcessingInstructions,
                DtdProcessing                = dtdProcessing,
                ConformanceLevel             = level,
                ValidationFlags              = validationFlags,
                ValidationType               = validationType,
                Schemas     = schemaSet,
                XmlResolver = resolver ?? XmlUrlResolverHelper.CreateResolver()
            };

            if (onErrorHandler != null)
            {
                settings.ValidationEventHandler += onErrorHandler;
            }
            return(settings);
        }
예제 #42
0
파일: XmlDocument.cs 프로젝트: nzaugg/mono
		private void Validate (ValidationEventHandler handler,
			XmlNode node, XmlSchemaValidationFlags flags)
		{
			XmlReaderSettings settings = new XmlReaderSettings ();
			settings.NameTable = NameTable;
			settings.Schemas = schemas;
			settings.Schemas.XmlResolver = resolver;
			settings.XmlResolver = resolver;
			settings.ValidationFlags = flags;
			settings.ValidationType = ValidationType.Schema;
			XmlReader r = XmlReader.Create (
				new XmlNodeReader (node), settings);
			while (!r.EOF)
				r.Read ();
		}
 // Constructors
 public XmlSchemaValidator(System.Xml.XmlNameTable nameTable, XmlSchemaSet schemas, System.Xml.IXmlNamespaceResolver namespaceResolver, XmlSchemaValidationFlags validationFlags)
 {
 }
예제 #44
0
        public void CheckNoNamespaceSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator     val;
            XmlSchemaSet           schemas = new XmlSchemaSet();
            XmlSchemaInfo          info    = new XmlSchemaInfo();
            CValidationEventHolder holder  = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val                         = CreateValidator(schemas, allFlags);
            val.XmlResolver             = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "type1", null, null, TestData + XSDFILE_NO_TARGET_NAMESPACE);

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                //XmlExceptionVerifier.IsExceptionOk(holder.lastException);
            }

            return;
        }
예제 #45
0
        public void ValidateWithXmlReader(XmlSchemaSet schemas, string xml, string xsd)
        {
            XmlNamespaceManager      namespaceManager = new XmlNamespaceManager(new NameTable());
            XmlSchemaValidationFlags validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                                        XmlSchemaValidationFlags.AllowXmlAttributes;
            XmlSchemaValidator validator = new XmlSchemaValidator(namespaceManager.NameTable, schemas, namespaceManager, validationFlags);

            validator.Initialize();
            using (XmlReader r = XmlReader.Create(xsd))
            {
                while (r.Read())
                {
                    switch (r.NodeType)
                    {
                    case XmlNodeType.Element:
                        namespaceManager.PushScope();
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                if (r.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                                {
                                    namespaceManager.AddNamespace(r.LocalName, r.Value);
                                }
                            } while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        validator.ValidateElement(r.LocalName, r.NamespaceURI, null, null, null, null, null);
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                if (r.NamespaceURI != "http://www.w3.org/2000/xmlns/")
                                {
                                    validator.ValidateAttribute(r.LocalName, r.NamespaceURI, r.Value, null);
                                }
                            } while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        validator.ValidateEndOfAttributes(null);
                        if (r.IsEmptyElement)
                        {
                            goto case XmlNodeType.EndElement;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        validator.ValidateEndElement(null);
                        namespaceManager.PopScope();
                        break;

                    case XmlNodeType.Text:
                        validator.ValidateText(r.Value);
                        break;

                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.Whitespace:
                        validator.ValidateWhitespace(r.Value);
                        break;

                    default:
                        break;
                    }
                }
                validator.EndValidation();
            }
            XmlReaderSettings rs = new XmlReaderSettings();

            rs.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            rs.ValidationType          = ValidationType.Schema;
            rs.Schemas.XmlResolver     = new XmlUrlResolver();
            rs.Schemas.Add(null, XmlReader.Create(xsd));

            using (XmlReader r = XmlReader.Create(xml, rs))
            {
                while (r.Read())
                {
                    ;
                }
            }
            Assert.Equal(warningCount, 0);
            Assert.Equal(errorCount, 0);
        }