当前位置: 首页>>代码示例>>C#>>正文


C# Xml.XmlReaderSettings类代码示例

本文整理汇总了C#中System.Xml.XmlReaderSettings的典型用法代码示例。如果您正苦于以下问题:C# XmlReaderSettings类的具体用法?C# XmlReaderSettings怎么用?C# XmlReaderSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlReaderSettings类属于System.Xml命名空间,在下文中一共展示了XmlReaderSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixNuSpec

        private static void FixNuSpec(ProjectVersion version, string file)
        {
            XNamespace ns = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd";
            var readerSettings = new XmlReaderSettings
            {
                IgnoreComments = false,
                IgnoreWhitespace = false         
            };
            XDocument doc;
            using (var reader = XmlReader.Create(file, readerSettings))
            {
                doc = XDocument.Load(reader);
            }
            var versionElement = doc.Descendants(ns + "version").Single();
            versionElement.Value = version.FullText;
            var dependency = doc.Descendants(ns + "dependency").Where(x => (string)x.Attribute("id") == "NodaTime").FirstOrDefault();
            if (dependency != null)
            {
                dependency.SetAttributeValue("version", version.Dependency);
            }

            var writerSettings = new XmlWriterSettings
            {
                Encoding = new UTF8Encoding(false),
                Indent = false,
                NewLineHandling = NewLineHandling.None,
            };

            using (var writer = XmlWriter.Create(file, writerSettings))
            {
                doc.Save(writer);
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:33,代码来源:Program.cs

示例2: XmlResolver

		public void XmlResolver ()
		{
			XmlReaderSettings xrs = new XmlReaderSettings ();
			// setter-only property
			xrs.XmlResolver = new ConcreteXmlResolver ();
			xrs.XmlResolver = null;
		}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:XmlReaderSettingsTest.cs

示例3: GetPatents

        //read XML file for patent info
        public static SortedList<int, Patent> GetPatents()
        {
            XmlDocument doc = new XmlDocument();

            //if file doesn't exist, create it
            if (!File.Exists("Patents.xml"))
                doc.Save("Patents.xml");

            SortedList<int, Patent> patents = new SortedList<int, Patent>();

            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.IgnoreWhitespace = true;
            readerSettings.IgnoreComments = true;

            XmlReader readXml = null;

            try
            {
                readXml = XmlReader.Create(path, readerSettings);

                if (readXml.ReadToDescendant("Patent")) //read to first Patent node
                {
                    do
                    {
                        Patent patent = new Patent();
                        patent.Number = Convert.ToInt32(readXml["Number"]);
                        readXml.ReadStartElement("Patent");
                        patent.AppNumber = readXml.ReadElementContentAsString();
                        patent.Description = readXml.ReadElementContentAsString();
                        patent.FilingDate = DateTime.Parse(readXml.ReadElementContentAsString());
                        patent.Inventor = readXml.ReadElementContentAsString();
                        patent.Inventor2 = readXml.ReadElementContentAsString();

                        int key = patent.Number; //assign key to value

                        patents.Add(key, patent); //add key-value pair to list
                    }
                    while (readXml.ReadToNextSibling("Patent"));
                }
            }
            catch (XmlException ex)
            {
                MessageBox.Show(ex.Message, "Xml Error");
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "IO Exception");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception Occurred");
            }
            finally
            {
                if (readXml != null)
                    readXml.Close();
            }

            return patents;
        }
开发者ID:whitneyhaddow,项目名称:cat-patents-v2,代码行数:61,代码来源:PatentDB.cs

示例4: CreateXmlReaderSettings

 private static XmlReaderSettings CreateXmlReaderSettings(XmlSchema xmlSchema)
 {
     XmlReaderSettings settings = new XmlReaderSettings();
     settings.ValidationType = ValidationType.Schema;
     settings.Schemas.Add(xmlSchema);
     return settings;
 }
开发者ID:SaintLoong,项目名称:UltraNuke_Library,代码行数:7,代码来源:XmlSchemas.cs

示例5: Read

        /// <summary>
        /// Reads the PAP message from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        public static PapMessage Read(Stream stream)
        {
            XmlReaderSettings settings =
                new XmlReaderSettings
                {
                    CheckCharacters = true,
                    CloseInput = true,
                    ConformanceLevel = System.Xml.ConformanceLevel.Document,
                    DtdProcessing = DtdProcessing.Parse,
                    IgnoreComments = true,
                    ValidationType = ValidationType.DTD
                };
            XmlReader reader = XmlReader.Create(stream, settings);
            try
            {
                // Deserialize the data
                XmlSerializer serializer = new XmlSerializer(typeof(PapRoot));
                object resultRoot = serializer.Deserialize(reader);

                // Extract the response object from the appropriate root
                PapMessage response = null;
                if (resultRoot is PapRoot)
                {
                    response = ((PapRoot)resultRoot).Response;
                }

                return response;
            }
            finally
            {
                reader.Close();
            }
        }
开发者ID:ngoossens,项目名称:PushSharp,代码行数:38,代码来源:PapMessageParser.cs

示例6: StartupLoad

        private void StartupLoad()
        {
            // Init class properties
            SearchTypes = new List<string>();

            // Load stuff
            XmlReaderSettings settingsReaderSettings = new XmlReaderSettings();
            settingsReaderSettings.ValidationType = ValidationType.Schema;
            try
            {
                settingsReaderSettings.Schemas.Add("http://www.w3.org/2001/XMLSchema", "SettingsSchema.xsd");
            }
            catch (System.IO.IOException e)
            {
                ErrorDialogs.DetailedError("IO Exception", "Unable to read critical config file SettingsSchema.xsd.", e.Message);
                throw;
            }

            // Settings
            XmlReader settingsFileReader;
            try
            {
                settingsFileReader = XmlReader.Create("Settings.xml", settingsReaderSettings);
            }
            catch (System.IO.IOException e)
            {
                ErrorDialogs.DetailedError("IO Exception", "Unable to read critical config file Settings.xml.", e.Message);
                throw;
            }
            settingsFileReader.MoveToContent();
            settingsFileReader.ReadToFollowing("SearchType");
            SearchTypes.Add(settingsFileReader.GetAttribute("Name"));
            settingsFileReader.Close();
        }
开发者ID:Outrigger047,项目名称:Starfire,代码行数:34,代码来源:MainWindowLoadMethods.cs

示例7: ReadXml

        private static byte[] ReadXml(Stream data)
        {
            data.Position = 0;

            var settings = new XmlReaderSettings
            {
                CloseInput = false,
                IgnoreComments = true,
                IgnoreWhitespace = true,
                IgnoreProcessingInstructions = true,
            };

            using (var reader = XmlReader.Create(data, settings))
            {
                try
                {
                    if (!reader.ReadToFollowing("KeyFile"))
                        return null;

                    if (!reader.ReadToDescendant("Key"))
                        return null;

                    if (!reader.ReadToDescendant("Data"))
                        return null;

                    var base64 = reader.ReadElementContentAsString();
                    return Convert.FromBase64String(base64);
                }
                catch (XmlException)
                {
                    return null;
                }
            }
        }
开发者ID:MarioBinder,项目名称:7Pass,代码行数:34,代码来源:KeyFile.cs

示例8: LoadFromXml

        private static IEnumerable<StorageAccountAdapter> LoadFromXml()
        {
            List<StorageAccountAdapter> accounts = new List<StorageAccountAdapter>();

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;

            using (XmlReader reader = XmlReader.Create("accounts.xml"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(reader);

                var nodes = doc.DocumentElement.SelectNodes("/accounts/account").OfType<XmlNode>().ToList();
                foreach (XmlNode node in nodes)
                {
                    StorageAccountAdapter adapter = CreateAccount(node);
                    if (adapter != null)
                    {
                        accounts.Add(adapter);
                    }
                }
            }

            return accounts.OrderBy(f => f.Name);
        }
开发者ID:gest01,项目名称:BetterStorageExplorer,代码行数:25,代码来源:StorageAccountXmlSource.cs

示例9: LoadRuleFile

        private void LoadRuleFile()
        {
            if (string.IsNullOrEmpty(_fileName))
            {
                throw new NullReferenceException("Please set file name first");
            }
            if (!File.Exists(_fileName))
            {
                throw new Exception(string.Format("File {0} does not exists on disk",Path.GetFullPath(_fileName)));
            }

            using (Stream stream = File.OpenRead(_fileName))
            {
                var settings = new XmlReaderSettings
                {
                    ValidationType = ValidationType.Schema,
                };
                using (XmlReader reader = XmlReader.Create(stream, settings))
                {
                    XDocument fileDocument = XDocument.Load(reader, LoadOptions.PreserveWhitespace);
                    LoadRulesData(fileDocument);
                    reader.Close();
                }
                stream.Close();
            }
        }
开发者ID:rajeshwarn,项目名称:fb2converters,代码行数:26,代码来源:FileBasedConverter.cs

示例10: ReadAsXmlReader

        public static XmlReader ReadAsXmlReader(this HttpContent content, XmlReaderSettings settings)
        {
            FX.ThrowIfNull(content, "content");
            FX.ThrowIfNull(content, "settings");

            return XmlReader.Create(content.ContentReadStream, settings);
        }
开发者ID:AlexZeitler,项目名称:WcfHttpMvcFormsAuth,代码行数:7,代码来源:XmlReaderContentExtensions.cs

示例11: Validate

        public bool Validate()
        {
            is_success_ = false;

            XmlDocument document = new XmlDocument();
            document.Load(xml_filename_);

            XmlReaderSettings setting = new XmlReaderSettings();
            setting.CloseInput = true;
            setting.ValidationEventHandler += Handler;
            setting.ValidationType = ValidationType.Schema;
            setting.Schemas.Add(null, xsd_filename_);
            setting.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings |
                                      XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                      XmlSchemaValidationFlags.ProcessInlineSchema |
                                      XmlSchemaValidationFlags.ProcessSchemaLocation;

            is_success_ = true;

            using (XmlReader validationReader = XmlReader.Create(xml_filename_, setting))
            {
                while (validationReader.Read())
                {
                    /* do nothing for while */
                }
            }

            return is_success_;
        }
开发者ID:zelon,项目名称:xml-xsd-validator,代码行数:29,代码来源:Validator.cs

示例12: CreateXmlReader

        private XmlReader CreateXmlReader()
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;

            return XmlTextReader.Create(_fs, settings);
        }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:7,代码来源:MainForm.cs

示例13: LoadTextSource

        /// <summary>
        /// Loads the WorldMarket data from text source.
        /// </summary>
        /// <param name="xmlText">The UTF-8 text source.</param>
        public static WorldMarket LoadTextSource(string xmlText)
        {
            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
#if !(NETFX_CORE || SILVERLIGHT)
                XmlSchema sch = XmlSchema.Read(new System.IO.StringReader(Properties.Resources.market_schema), null);
                readerSettings.Schemas.Add(sch);
                readerSettings.ValidationType = ValidationType.Schema;
#endif
                XmlReader market = XmlReader.Create(new System.IO.StringReader(xmlText), readerSettings);
                XmlSerializer ser = new XmlSerializer(typeof(System.Resources.WorldMarket));

                System.Resources.WorldMarket wm = (System.Resources.WorldMarket)ser.Deserialize(market);

                WorldMarket result = new WorldMarket();

                foreach (var s in wm.Sectors) { result.mSectors.Add(new Sector(s)); }
                foreach (var s in wm.Industries) { result.mIndustries.Add(new Industry(s, result)); }
                foreach (var s in wm.Currencies) { result.mCurrencies.Add(new CurrencyInfo(s)); }
                foreach (var s in wm.Countries) { result.mCountries.Add(new CountryInfo(s, result)); }
                foreach (var s in wm.StockExchanges) { result.mStockExchanges.Add(new StockExchange(s, result)); }
                foreach (var s in wm.Indices) { result.mIndices.Add(new YID(s, result)); }
                foreach (var s in wm.FundCategories) { result.mFundCategories.Add(new FundCategory(s)); }
                foreach (var s in wm.FundFamilies) { result.mFundFamilies.Add(new FundFamily(s)); }

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("The XML text is not valid. See InnerException for more details.", ex);
            }
        }
开发者ID:jrwren,项目名称:yahoofinance,代码行数:37,代码来源:WorldMarket.cs

示例14: PairNodes

        public void PairNodes(Node node1, Node node2)
        {
            try
            {
                XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
                xmlReaderSettings.IgnoreWhitespace = true;
                xmlReaderSettings.IgnoreComments = true;

                //if (!File.Exists(XmlFilePath)) return;
                var document = new XmlDocument();
                document.Load(XmlFilePath);

                var xmlElementList = document.GetElementsByTagName("NodePairs");
                var newXmlElement = document.CreateElement("NodePair");
                var firstNode = document.CreateElement("Node");
                var secondNode = document.CreateElement("Node");
                firstNode.SetAttribute("Id", node1.Id);
                secondNode.SetAttribute("Id", node2.Id);
                newXmlElement.AppendChild(firstNode);
                newXmlElement.AppendChild(secondNode);
                xmlElementList[0].AppendChild(newXmlElement);
                document.Save(XmlFilePath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:tomtung,项目名称:Ycyj.Client,代码行数:28,代码来源:NodePairManager.cs

示例15: LoadScript

        private static Script LoadScript(string fileName)
        {
            try
            {
                var settings = new XmlReaderSettings();

                string resourceName = typeof(ScriptLoader).Namespace + ".Script-v1.xsd";

                using (var stream = typeof(ScriptLoader).Assembly.GetManifestResourceStream(resourceName))
                using (var reader = XmlReader.Create(stream))
                {
                    settings.Schemas.Add(Constants.ScriptNs, reader);
                }

                settings.ValidationType = ValidationType.Schema;

                using (var reader = XmlReader.Create(fileName, settings))
                {
                    var serializer = new XmlSerializer(typeof(Script));

                    return (Script)serializer.Deserialize(reader);
                }
            }
            catch (Exception ex)
            {
                throw new ScriptException(UILabels.InvalidScript, ex);
            }
        }
开发者ID:pvginkel,项目名称:NuGetUpdate,代码行数:28,代码来源:ScriptLoader.cs


注:本文中的System.Xml.XmlReaderSettings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。