• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Xml.XmlReaderSettings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ToHtml

        private string ToHtml()
        {
            if (Services.StrandsCache.Contains(this))
            {
                return Services.StrandsCache.Read(this);
            }
            else
            {
                var transform = new XslCompiledTransform(true);
                var arguments = new XsltArgumentList();
                var settings = new XsltSettings();
                var readersettings = new XmlReaderSettings();
                //string xslsrc = (!string.IsNullOrEmpty(this.DisplayType)) ? "/XMLList.xsl" : "/Strands.xsl";
                //var xslfile = (this.Name == "themes") ? HttpContext.Current.Server.MapPath(this._xslAppUrl + "/StrandList.xsl") : HttpContext.Current.Server.MapPath(this._xslAppUrl + xslsrc);
                var xslfile = HttpContext.Current.Server.MapPath(this._xslAppUrl + ((!string.IsNullOrEmpty(this.DisplayType)) ? "XMLList.xsl" : this.XslName));

                settings.EnableDocumentFunction = true;
                settings.EnableScript = true;
                readersettings.DtdProcessing = DtdProcessing.Parse;
                readersettings.ValidationType = ValidationType.None;
                transform.Load(xslfile, settings, new XmlUrlResolver());
                arguments = TransformArguments(this);
                using (XmlReader reader = XmlReader.Create(this.GetDirectoryPath(), readersettings))
                {
                    System.IO.StringWriter writer = new System.IO.StringWriter();

                    transform.Transform(reader, arguments, writer);
                    return Services.StrandsCache.Write(this, writer.ToString());
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcStrands_git,代码行数:31,代码来源:StrandsRepository.cs


示例17: Validate_Against_Schema

        /// <summary> Validates a single METS XML file </summary>
        /// <param name="METS_File"> Location and name of file to validate </param>
        /// <returns> TRUE if it validates, otherwise FALSE </returns>
        /// <remarks> If this does not validate, the accumulated errors can be reached through the 'Errors' property. </remarks>
        public bool Validate_Against_Schema(string METS_File)
        {
            try
            {
                // Set some initial values
                isValid = true;
                errors = new StringBuilder();

                // Create the reader and validator
                XmlReaderSettings metsSettings = new XmlReaderSettings();
                metsSettings.Schemas.Add(cache);
                metsSettings.ValidationType = ValidationType.Schema;
                metsSettings.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler);

                XmlReader validator = XmlReader.Create(METS_File, metsSettings);

                // Step through the XML file
                while (validator.Read())
                {
                    /* Just reading through, looking for problems... */
                }
                validator.Close();

                // Return the valid flag
                return isValid;
            }
            catch
            {
                errors.Append("UNSPECIFIED ERROR CAUGHT DURING VALIDATION");
                return false;
            }
        }
开发者ID:randomyed,项目名称:SobekCM-Web-Application,代码行数:36,代码来源:METS_Validator_Object.cs


示例18: XmlDocumentDeserializer

 static Book[] XmlDocumentDeserializer(string path)
 {
     XmlDocument doc = new XmlDocument();
     XmlReaderSettings settings = new XmlReaderSettings();
     settings.IgnoreComments = true;
     XmlReader reader = XmlReader.Create(path, settings);
     doc.Load(reader);
     if(doc == null)
     {
         return null;
     }
     List<Book> bookList = new List<Book>();
     XmlNode xn = doc.SelectSingleNode("bookstore");
     XmlNodeList xnl = xn.ChildNodes;
     foreach(XmlNode _xn in xnl)
     {
         Book book = new Book();
         XmlElement xe = (XmlElement)_xn;
         book.Type = xe.GetAttribute("Type").ToString();
         book.ISBN = xe.GetAttribute("ISBN").ToString();
         XmlNodeList _xnl = xe.ChildNodes;
         book.Name = _xnl.Item(0).InnerText;
         book.Author = _xnl.Item(1).InnerText;
         float price;
         if(float.TryParse(_xnl.Item(2).InnerText,out price))
         {
             book.Price = price;
         }
         bookList.Add(book);
     }
     return bookList.ToArray();
 }
开发者ID:FinleySmile,项目名称:CSharpStudy,代码行数:32,代码来源:Program.cs


示例19: DnaXmlValidator

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="xml">XML to validate</param>
        /// <param name="schemaUri">Schema Uri</param>
        public DnaXmlValidator(string xml, string schemaUri)
        {
            _schemaUri = schemaUri;
            // set up the schema
            LoadSchema(schemaUri);

            // set up the xml reader
            _rawXml = xml;
            _xml = new StringReader(xml);

            // set up the settings for validating the xml
            _validationSettings = new XmlReaderSettings();
            _validationSettings.Schemas.Add(_xmlSchema);
            _validationSettings.IgnoreWhitespace = true;
            _validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
            _validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
            _validationSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
            _validationSettings.ValidationType = ValidationType.Schema;
            try
            {
                _validationSettings.Schemas.Compile();
            }
            catch (XmlSchemaException e)
            {
                string s = e.SourceUri;
            }
            _validationSettings.ValidationEventHandler += new ValidationEventHandler(xmlReaderSettingsValidationEventHandler);
            _validationSettings.DtdProcessing = DtdProcessing.Parse;
            // set the the XmlReader for validation
            _validator = XmlReader.Create(_xml, _validationSettings);
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:36,代码来源:DnaXmlValidator.cs


示例20: btnDisplay_Click

        protected void btnDisplay_Click(object sender, EventArgs e)
        {
            //XML文件所在位置
            string xmlFilePath = Server.MapPath(@"Docs\Book1.xml");

            //创建XmlReaderSettings对象,并设置适合的属性
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;

            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(null, Server.MapPath(@"Docs\Book.xsd"));
            settings.IgnoreWhitespace = false;

            try
            {
                //引用XMLReader对象,并指定设置
                XmlReader reader = XmlReader.Create(xmlFilePath, settings);

                while (reader.Read())
                {
                    Response.Write(reader.Value + "<br/>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("An Exception: " + ex.Message);
            }
        }
开发者ID:ningboliuwei,项目名称:Course_XML,代码行数:28,代码来源:XmlReaderExample_Validation.aspx.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Xml.XmlResolver类代码示例发布时间:2022-05-27
下一篇:
C# Media3D.Point3D类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap