System.Configuration.MgmtConfigurationRecord.ValidateSectionXml C# (CSharp) Method

ValidateSectionXml() private method

private ValidateSectionXml ( string xmlElement, string configKey ) : void
xmlElement string
configKey string
return void
        private void ValidateSectionXml(string xmlElement, string configKey) {
            if (string.IsNullOrEmpty(xmlElement))
                return;

            XmlTextReader reader = null;
            try {
                XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.Default, Encoding.Unicode);
                reader = new XmlTextReader(xmlElement, XmlNodeType.Element, context);

                // Verify that the it is an element
                reader.Read();
                if (reader.NodeType != XmlNodeType.Element) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_unexpected_node_type, reader.NodeType));
                }

                // Verify the name of the element is a section
                string group, name;
                SplitConfigKey(configKey, out group, out name);
                if (reader.Name != name) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_unexpected_element_name, reader.Name));
                }

                for (;;) {
                    if (!reader.Read()) {
                        // ensure there is a matching end element
                        if (reader.Depth != 0) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_unexpected_element_end),reader);
                        }

                        break;
                    }

                    switch (reader.NodeType) {
                        // disallowed node types within a section
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.DocumentType:
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_node_type),reader);

                        default:
                            break;
                    }


                    // don't allow XML after the end element
                    if (reader.Depth <= 0 && reader.NodeType != XmlNodeType.EndElement) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_more_data_than_expected),reader);
                    }
                }
            }
            finally {
                if (reader != null) {
                    reader.Close();
                }
            }
        }