GetParentElement() private method

private GetParentElement ( ) : ConfigurationElement
return ConfigurationElement
        internal object ExtractDefaultValueFromSchema()
        {
            object defaultValue;

            if (_element.FileContext.Parent != null)
            {
                // web.config
                var parentElementInFile = _element.GetParentElement();
                defaultValue = parentElementInFile == null ? Schema?.DefaultValue : parentElementInFile.Attributes[Name].Value;
            }
            else if (_element.Section?.Location == null)
            {
                // root config
                defaultValue = Decrypt(Schema?.DefaultValue);
            }
            else
            {
                // location tags in applicationHost.config.
                var parentElement = _element.GetElementAtParentLocationInFileContext(_element.FileContext);
                defaultValue = parentElement == null ? Schema?.DefaultValue : parentElement.Attributes[Name].Value;
            }

            if (defaultValue == null)
            {
                // IMPORTANT: to set default values so that in configuration files they do not appear.
                if (Schema != null)
                {
                    if (Schema.DefaultValue == null)
                    {
                        try
                        {
                            Schema.SetDefaultValue(Schema.DefaultValueByType);
                        }
                        catch (COMException)
                        {
                            // IMPORTANT: If validators do not like default value, simply ignore.
                            return(defaultValue = Schema.DefaultValueByType);
                        }

                        defaultValue = Schema.DefaultValue;
                    }
                }
            }

            return(defaultValue);
        }