System.Xml.DocumentSchemaValidator.GetTypeFromAncestors C# (CSharp) Méthode

GetTypeFromAncestors() private méthode

private GetTypeFromAncestors ( XmlElement elementToValidate, XmlSchemaObject ancestorType, int ancestorsCount ) : XmlSchemaObject
elementToValidate XmlElement
ancestorType System.Xml.Schema.XmlSchemaObject
ancestorsCount int
Résultat System.Xml.Schema.XmlSchemaObject
        private XmlSchemaObject GetTypeFromAncestors(XmlElement elementToValidate, XmlSchemaObject ancestorType, int ancestorsCount)
        {
            //schemaInfo is currentNode's schemaInfo
            _validator = CreateTypeFinderValidator(ancestorType);
            _schemaInfo = new XmlSchemaInfo();

            //start at the ancestor to start validating
            int startIndex = ancestorsCount - 1;

            bool ancestorHasWildCard = AncestorTypeHasWildcard(ancestorType);
            for (int i = startIndex; i >= 0; i--)
            {
                XmlNode node = _nodeSequenceToValidate[i];
                XmlElement currentElement = node as XmlElement;
                ValidateSingleElement(currentElement, false, _schemaInfo);
                if (!ancestorHasWildCard)
                { //store type if ancestor does not have wildcard in its content model
                    currentElement.XmlName = _document.AddXmlName(currentElement.Prefix, currentElement.LocalName, currentElement.NamespaceURI, _schemaInfo);
                    //update wildcard flag
                    ancestorHasWildCard = AncestorTypeHasWildcard(_schemaInfo.SchemaElement);
                }

                _validator.ValidateEndOfAttributes(null);
                if (i > 0)
                {
                    ValidateChildrenTillNextAncestor(node, _nodeSequenceToValidate[i - 1]);
                }
                else
                { //i == 0
                    ValidateChildrenTillNextAncestor(node, elementToValidate);
                }
            }

            Debug.Assert(_nodeSequenceToValidate[0] == elementToValidate.ParentNode);
            //validate element whose type is needed,
            ValidateSingleElement(elementToValidate, false, _schemaInfo);

            XmlSchemaObject schemaInfoFound = null;
            if (_schemaInfo.SchemaElement != null)
            {
                schemaInfoFound = _schemaInfo.SchemaElement;
            }
            else
            {
                schemaInfoFound = _schemaInfo.SchemaType;
            }
            if (schemaInfoFound == null)
            { //Detect if the node was validated lax or skip
                if (_validator.CurrentProcessContents == XmlSchemaContentProcessing.Skip)
                {
                    if (_isPartialTreeValid)
                    { //Then node assessed as skip; if there was error we turn processContents to skip as well. But this is not the same as validating as skip.
                        return XmlSchemaComplexType.AnyTypeSkip;
                    }
                }
                else if (_validator.CurrentProcessContents == XmlSchemaContentProcessing.Lax)
                {
                    return XmlSchemaComplexType.AnyType;
                }
            }
            return schemaInfoFound;
        }