ParseReaderNode() public méthode

public ParseReaderNode ( ) : bool
Résultat bool
 private void ProcessInlineSchema()
 {
     if (!inlineSchemaParser.ParseReaderNode())   // Done
     {
         inlineSchemaParser.FinishParsing();
         XmlSchema schema   = inlineSchemaParser.XmlSchema;
         string    inlineNS = null;
         if (schema != null && schema.ErrorCount == 0)
         {
             try {
                 SchemaInfo inlineSchemaInfo = new SchemaInfo();
                 inlineSchemaInfo.SchemaType = SchemaType.XSD;
                 inlineNS = schema.TargetNamespace == null? string.Empty : schema.TargetNamespace;
                 if (!SchemaInfo.TargetNamespaces.ContainsKey(inlineNS))
                 {
                     if (SchemaCollection.Add(inlineNS, inlineSchemaInfo, schema, true) != null)   //If no errors on compile
                     //Add to validator's SchemaInfo
                     {
                         SchemaInfo.Add(inlineSchemaInfo, EventHandler);
                     }
                 }
             }
             catch (XmlSchemaException e) {
                 SendValidationEvent(Res.Sch_CannotLoadSchema, new string[] { BaseUri.AbsoluteUri, e.Message }, XmlSeverityType.Error);
             }
         }
         inlineSchemaParser = null;
     }
 }
Exemple #2
0
 private void ValidateElement()
 {
     elementName.Init(reader.LocalName, XmlSchemaDatatype.XdrCanonizeUri(reader.NamespaceURI, NameTable, SchemaNames));
     ValidateChildElement();
     if (SchemaNames.IsXDRRoot(elementName.Name, elementName.Namespace) && reader.Depth > 0)
     {
         _inlineSchemaParser = new Parser(SchemaType.XDR, NameTable, SchemaNames, EventHandler);
         _inlineSchemaParser.StartParsing(reader, null);
         _inlineSchemaParser.ParseReaderNode();
     }
     else
     {
         ProcessElement();
     }
 }
        private void ValidateElement()
        {
            elementName.Init(reader.LocalName, reader.NamespaceURI);
            object particle = ValidateChildElement();

            if (IsXSDRoot(elementName.Name, elementName.Namespace) && reader.Depth > 0)
            {
                inlineSchemaParser = new Parser(SchemaType.XSD, NameTable, SchemaNames, EventHandler);
                inlineSchemaParser.StartParsing(reader, null);
                inlineSchemaParser.ParseReaderNode();
            }
            else
            {
                ProcessElement(particle);
            }
        }
Exemple #4
0
 private void ProcessInlineSchema()
 {
     if (!_inlineSchemaParser.ParseReaderNode())
     { // Done
         _inlineSchemaParser.FinishParsing();
         SchemaInfo xdrSchema = _inlineSchemaParser.XdrSchema;
         if (xdrSchema != null && xdrSchema.ErrorCount == 0)
         {
             foreach (string inlineNS in xdrSchema.TargetNamespaces.Keys)
             {
                 if (!this.schemaInfo.HasSchema(inlineNS))
                 {
                     schemaInfo.Add(xdrSchema, EventHandler);
                     SchemaCollection.Add(inlineNS, xdrSchema, null, false);
                     break;
                 }
             }
         }
         _inlineSchemaParser = null;
     }
 }
        // SxS: This function calls ValidateElement on XmlSchemaValidator which is annotated with ResourceExposure attribute.
        // Since the resource names (namespace location) are not provided directly by the user (they are read from the source
        // document) and the function does not expose any resources it is fine to suppress the SxS warning.
        private async Task ProcessElementEventAsync()
        {
            if (_processInlineSchema && IsXSDRoot(_coreReader.LocalName, _coreReader.NamespaceURI) && _coreReader.Depth > 0)
            {
                _xmlSchemaInfo.Clear();
                _attributeCount = _coreReaderAttributeCount = _coreReader.AttributeCount;
                if (!_coreReader.IsEmptyElement)
                { //If its not empty schema, then parse else ignore
                    _inlineSchemaParser = new Parser(SchemaType.XSD, _coreReaderNameTable, _validator.SchemaSet.GetSchemaNames(_coreReaderNameTable), _validationEvent);
                    await _inlineSchemaParser.StartParsingAsync(_coreReader, null).ConfigureAwait(false);
                    _inlineSchemaParser.ParseReaderNode();
                    _validationState = ValidatingReaderState.ParseInlineSchema;
                }
                else
                {
                    _validationState = ValidatingReaderState.ClearAttributes;
                }
            }
            else
            { //Validate element
                //Clear previous data
                _atomicValue = null;
                _originalAtomicValueString = null;
                _xmlSchemaInfo.Clear();

                if (_manageNamespaces)
                {
                    _nsManager.PushScope();
                }
                //Find Xsi attributes that need to be processed before validating the element
                string xsiSchemaLocation = null;
                string xsiNoNamespaceSL = null;
                string xsiNil = null;
                string xsiType = null;
                if (_coreReader.MoveToFirstAttribute())
                {
                    do
                    {
                        string objectNs = _coreReader.NamespaceURI;
                        string objectName = _coreReader.LocalName;
                        if (Ref.Equal(objectNs, _nsXsi))
                        {
                            if (Ref.Equal(objectName, _xsiSchemaLocation))
                            {
                                xsiSchemaLocation = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiNoNamespaceSchemaLocation))
                            {
                                xsiNoNamespaceSL = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiType))
                            {
                                xsiType = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiNil))
                            {
                                xsiNil = _coreReader.Value;
                            }
                        }
                        if (_manageNamespaces && Ref.Equal(_coreReader.NamespaceURI, _nsXmlNs))
                        {
                            _nsManager.AddNamespace(_coreReader.Prefix.Length == 0 ? string.Empty : _coreReader.LocalName, _coreReader.Value);
                        }
                    } while (_coreReader.MoveToNextAttribute());
                    _coreReader.MoveToElement();
                }
                _validator.ValidateElement(_coreReader.LocalName, _coreReader.NamespaceURI, _xmlSchemaInfo, xsiType, xsiNil, xsiSchemaLocation, xsiNoNamespaceSL);
                ValidateAttributes();
                _validator.ValidateEndOfAttributes(_xmlSchemaInfo);
                if (_coreReader.IsEmptyElement)
                {
                    await ProcessEndElementEventAsync().ConfigureAwait(false);
                }
                _validationState = ValidatingReaderState.ClearAttributes;
            }
        }
        private void ProcessElementEvent() {
            if (this.processInlineSchema && IsXSDRoot(coreReader.LocalName, coreReader.NamespaceURI) && coreReader.Depth > 0) {
                xmlSchemaInfo.Clear();
                attributeCount = coreReaderAttributeCount = coreReader.AttributeCount;
                if (!coreReader.IsEmptyElement) { //If its not empty schema, then parse else ignore
                    inlineSchemaParser = new Parser(SchemaType.XSD, coreReaderNameTable, validator.SchemaSet.GetSchemaNames(coreReaderNameTable), validationEvent);
                    inlineSchemaParser.StartParsing(coreReader, null);
                    inlineSchemaParser.ParseReaderNode();
                    validationState = ValidatingReaderState.ParseInlineSchema;
                }
                else {
                    validationState = ValidatingReaderState.ClearAttributes;
                }
            }
            else { //Validate element

                //Clear previous data
                atomicValue = null;
                originalAtomicValueString = null;
                xmlSchemaInfo.Clear();

                if (manageNamespaces) {
                    nsManager.PushScope();
                }
                //Find Xsi attributes that need to be processed before validating the element
                string xsiSchemaLocation = null;
                string xsiNoNamespaceSL = null;
                string xsiNil = null;
                string xsiType = null;
                if (coreReader.MoveToFirstAttribute()) {
                    do {
                        string objectNs = coreReader.NamespaceURI;
                        string objectName = coreReader.LocalName;
                        if (Ref.Equal(objectNs, NsXsi)) {
                            if (Ref.Equal(objectName, XsiSchemaLocation)) {
                                xsiSchemaLocation = coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, XsiNoNamespaceSchemaLocation)) {
                                xsiNoNamespaceSL = coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, XsiType)) {
                                xsiType = coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, XsiNil)) {
                                xsiNil = coreReader.Value;
                            }
                        }
                        if (manageNamespaces && Ref.Equal(coreReader.NamespaceURI, NsXmlNs)) {
                            nsManager.AddNamespace(coreReader.Prefix.Length == 0 ? string.Empty : coreReader.LocalName, coreReader.Value);
                        }

                    } while (coreReader.MoveToNextAttribute());
                    coreReader.MoveToElement();
                }
                validator.ValidateElement(coreReader.LocalName, coreReader.NamespaceURI, xmlSchemaInfo, xsiType, xsiNil, xsiSchemaLocation, xsiNoNamespaceSL);
                ValidateAttributes();
                validator.ValidateEndOfAttributes(xmlSchemaInfo);
                if (coreReader.IsEmptyElement) {
                    ProcessEndElementEvent();
                }
                validationState = ValidatingReaderState.ClearAttributes;
            }
        }
 private void ValidateElement() {
     elementName.Init(reader.LocalName, XmlSchemaDatatype.XdrCanonizeUri(reader.NamespaceURI, NameTable, SchemaNames));
     ValidateChildElement();
     if (SchemaNames.IsXDRRoot(elementName.Name, elementName.Namespace) && reader.Depth > 0) {
         inlineSchemaParser = new Parser(SchemaType.XDR, NameTable, SchemaNames, EventHandler);
         inlineSchemaParser.StartParsing(reader, null);
         inlineSchemaParser.ParseReaderNode();
     }
     else {
         ProcessElement();
     }
 }
Exemple #8
0
        internal void Validate() {
            if (inlineSchemaParser != null) {
                if (!inlineSchemaParser.ParseReaderNode()) { // Done
                    XmlSchema schema = inlineSchemaParser.FinishParsing();
                    bool add = true;
                    if (schema != null) {
                        inlineNs = schema.TargetNamespace == null ? string.Empty : schema.TargetNamespace;
                        if (!SchemaInfo.HasSchema(inlineNs) && schema.ErrorCount == 0) {
                            schema.Compile(schemaCollection, nameTable, schemaNames, validationEventHandler, null, inlineSchemaInfo, true);
                            add = schema.ErrorCount == 0;
                        }
                        else {
                            add = false;
                        }
                    }
                    else {
                        inlineNs = inlineSchemaInfo.CurrentSchemaNamespace;
                        add = !SchemaInfo.HasSchema(inlineNs);
                    }

                    if (add) {
                        SchemaInfo.Add(inlineNs, inlineSchemaInfo, validationEventHandler);
                        schemaCollection.Add(inlineNs, inlineSchemaInfo, schema, false);
                    }
                    inlineSchemaParser = null;
                    inlineSchemaInfo = null;
                    inlineNs = null;
                }
            }
            else {
                this.name = QualifiedName(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                if (HasSchema) {
                    if (context != null) {
                        while (context != null && reader.Depth <= context.Depth) {
                            EndChildren();
                        }
                        ValidateElementContent(reader.NodeType);
                    }
                    if (reader.Depth == 0 && reader.NodeType == XmlNodeType.Element && SchemaInfo.SchemaType == SchemaType.DTD) {
                        if (!SchemaInfo.DocTypeName.Equals(this.name)) {
                            SendValidationEvent(Res.Sch_RootMatchDocType);
                        }
                    }
                }
                if (reader.NodeType == XmlNodeType.Element) {
                    if (schemaNames.IsSchemaRoot(this.name) &&
                        !SkipProcess(this.name == schemaNames.QnXsdSchema ? SchemaType.XSD : SchemaType.XDR) &&
                        IsCorrectSchemaType(this.name == schemaNames.QnXsdSchema ? SchemaType.XSD : SchemaType.XDR)) {
                        inlineSchemaInfo = new SchemaInfo(schemaNames);
                        inlineSchemaParser = new Parser(schemaCollection, nameTable, schemaNames, validationEventHandler);
                        inlineSchemaParser.StartParsing(reader, null, inlineSchemaInfo);
                        inlineSchemaParser.ParseReaderNode();
                    }
                    else {
                        ProcessElement();
                    }
                }
            }
        }
 private void ValidateElement() {
     elementName.Init(reader.LocalName, reader.NamespaceURI);
     object particle = ValidateChildElement ();
     if (IsXSDRoot(elementName.Name, elementName.Namespace) && reader.Depth > 0) {
         inlineSchemaParser = new Parser(SchemaType.XSD, NameTable, SchemaNames, EventHandler);
         inlineSchemaParser.StartParsing(reader, null);
         inlineSchemaParser.ParseReaderNode();
     }
     else {
         ProcessElement(particle);
     }
 }