當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlTextReader.?.Close方法代碼示例

本文整理匯總了C#中System.Xml.XmlTextReader.?.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.?.Close方法的具體用法?C# XmlTextReader.?.Close怎麽用?C# XmlTextReader.?.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.?.Close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Load

 /// <summary>
 /// Read the .config from a file.
 /// </summary>
 /// <param name="appConfigFile"></param>
 internal void Load(string appConfigFile)
 {
     XmlTextReader reader = null;
     try
     {
         reader = new XmlTextReader(appConfigFile);
         reader.DtdProcessing = DtdProcessing.Ignore;
         Read(reader);
     }
     catch (XmlException e)
     {
         throw new AppConfigException(e.Message, appConfigFile, (reader != null ? reader.LineNumber : 0), (reader != null ? reader.LinePosition : 0), e);
     }
     catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
     {
         throw new AppConfigException(e.Message, appConfigFile, (reader != null ? reader.LineNumber : 0), (reader != null ? reader.LinePosition : 0), e);
     }
     finally
     {
         reader?.Close();
     }
 }
開發者ID:nikson,項目名稱:msbuild,代碼行數:26,代碼來源:AppConfig.cs

示例2: ValidateSectionXml

        // Verify that the string is valid xml, begins with the expected section name,
        // and contains no more or less than a single element.
        //
        // Throws a ConfigurationErrorsException if there is an error.
        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(string.Format(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(string.Format(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(string.Format(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.Config_invalid_node_type, reader);
                    }


                    // don't allow XML after the end element
                    if ((reader.Depth <= 0) && (reader.NodeType != XmlNodeType.EndElement))
                        throw new ConfigurationErrorsException(SR.Config_more_data_than_expected, reader);
                }
            }
            finally
            {
                reader?.Close();
            }
        }
開發者ID:chcosta,項目名稱:corefx,代碼行數:59,代碼來源:MgmtConfigurationRecord.cs


注:本文中的System.Xml.XmlTextReader.?.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。