Пример #1
0
 internal XmlValidatingReaderImpl(XmlReader reader, System.Xml.Schema.ValidationEventHandler settingsEventHandler, bool processIdentityConstraints)
 {
     this.parsingFunction = ParsingFunction.Init;
     this.outerReader     = this;
     this.coreReader      = reader;
     this.coreReaderImpl  = reader as XmlTextReaderImpl;
     if (this.coreReaderImpl == null)
     {
         XmlTextReader reader2 = reader as XmlTextReader;
         if (reader2 != null)
         {
             this.coreReaderImpl = reader2.Impl;
         }
     }
     if (this.coreReaderImpl == null)
     {
         throw new ArgumentException(Res.GetString("Arg_ExpectingXmlTextReader"), "reader");
     }
     this.coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
     this.coreReaderNSResolver         = reader as IXmlNamespaceResolver;
     this.processIdentityConstraints   = processIdentityConstraints;
     this.schemaCollection             = new XmlSchemaCollection(this.coreReader.NameTable);
     this.schemaCollection.XmlResolver = this.GetResolver();
     this.eventHandling = new ValidationEventHandling(this);
     if (settingsEventHandler != null)
     {
         this.eventHandling.AddHandler(settingsEventHandler);
     }
     this.coreReaderImpl.ValidationEventHandling = this.eventHandling;
     this.coreReaderImpl.OnDefaultAttributeUse   = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(this.ValidateDefaultAttributeOnUse);
     this.validationType = System.Xml.ValidationType.DTD;
     this.SetupValidation(System.Xml.ValidationType.DTD);
 }
Пример #2
0
        public void VaildateXMl()
        {
            string xsdPath = "person.xsd";
            string xmlPath = "person.xml";

            XmlReader   reader   = XmlReader.Create(xmlPath);
            XmlDocument document = new XmlDocument();

            document.Schemas.Add("", xsdPath);
            document.Load(reader);

            ValidationEventHandler eventHandler = new System.Xml.Schema.ValidationEventHandler(ValidationEventHandler);

            document.Validate(eventHandler);
        }