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


C# XmlDocument.Validate方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Validate方法的具体用法?C# XmlDocument.Validate怎么用?C# XmlDocument.Validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


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

示例1: Main

        internal static void Main()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("../../../correctXML.xml");
            doc.Schemas.Add("urn:catalogueSchema", "../../../catalogueSchema.xsd");

            ValidationEventHandler eventhandler = new ValidationEventHandler(ValidateEventHandler);
            doc.Validate(eventhandler);

            // I Just delete albums element.
            doc.Load("../../../invalidXML.xml");
            doc.Validate(eventhandler);
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:13,代码来源:XMLDocumnetValidator.cs

示例2: GetCustomersUsingXmlDocument

        /// <summary>
        /// ¬озвращает список клиентов прочитанный из указанного XML файла с помощью класса XmlDocument
        /// </summary>
        /// <param name="customersXmlPath">ѕуть к файлу customers.xml</param>
        /// <param name="customersXsdPath">ѕуть к файлу customers.xsd</param>
        /// <returns>Cписок клиентов</returns>
        /// <remarks>ќбратите внимание, что мы всегда возврашаем коллекцию даже если ничего не прочитали из файла</remarks>
        /// <exception cref="InvalidCustomerFileException">¬ходной файл не соответствует XML схеме</exception>
        public static List<Customer> GetCustomersUsingXmlDocument(string customersXmlPath, string customersXsdPath = null)
        {
            var customers = new List<Customer>();

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(customersXmlPath);
            if (customersXsdPath != null)
            {
                xmlDoc.Schemas.Add(CUSTOMERS_NAMESPACE, customersXsdPath);

                try
                {
                    xmlDoc.Validate(null);
                }
                catch (XmlSchemaValidationException ex)
                {
                    throw new InvalidCustomerFileException("Customer.xml has some errors", ex);
                }
            }

            var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
            nsmgr.AddNamespace("c", CUSTOMERS_NAMESPACE);

            XmlNodeList customerNodes = xmlDoc.DocumentElement.SelectNodes("c:Customer", nsmgr);
            foreach (XmlElement customerElement in customerNodes)
            {
                customers.Add(CreateCustomerFromXmlElement(customerElement, nsmgr));
            }

            return customers;
        }
开发者ID:bazile,项目名称:Training,代码行数:39,代码来源:CustomerReader.cs

示例3: ReadXml

        private XmlDocument ReadXml(string file) {
            TextReader xml = new StreamReader(file);
            XmlReader xsd = XmlReader.Create(new StreamReader("HVP_Transaction.xsd"));

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.Schemas.Add(null, xsd);
            settings.ValidationType = ValidationType.Schema;
            settings.ValidationEventHandler += new ValidationEventHandler(validationEventHandler);

            XmlReader reader = XmlReader.Create(xml, settings);
            XmlDocument document = new XmlDocument();

            valid = true;
            try
            {
                document.Load(reader);
                document.Validate(new ValidationEventHandler(validationEventHandler));
            }
            finally
            {
                reader.Close();
                xml.Close();
                xsd.Close();
                
            }

            return valid ? document : null;
        }
开发者ID:HVPA,项目名称:VariantExporter,代码行数:28,代码来源:XmlOutputTest.cs

示例4: Validate

 public static bool Validate(XmlDocument document, XmlSchema schema)
 {
     succes = true;
     document.Schemas.Add(schema);
     document.Validate(new ValidationEventHandler(ValidationCallBack));
     return succes;
 }
开发者ID:00Green27,项目名称:DocUI,代码行数:7,代码来源:XmlValidator.cs

示例5: Validate

        public Boolean Validate()
        {
            XmlTextReader txtreader = null;
            try
            {
                txtreader = new XmlTextReader(fileName);

                XmlDocument doc = new XmlDocument();
                doc.Load(txtreader);
                ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);

                doc.Validate(eventHandler);
            }
            catch (IOException e)
            {
                LogBookController.Instance.addLogLine("Error accessing chapter files. Probably doesn't exist. \n" + e, LogMessageCategories.Error);
               
                return false;
            }
            catch (XmlException e)
            {
                LogBookController.Instance.addLogLine("Error inside chapters XML file, trying again.\n" + e, LogMessageCategories.Error);
                return false;
            }
            finally
            {
                txtreader.Close();
            }

            return true;
        }
开发者ID:NeoBoy,项目名称:MiniCoder,代码行数:31,代码来源:XmlValidator.cs

示例6: Validate

        public Domain.ErrorCode Validate(IXPathNavigable configSectionNode)
        {
            log.Debug("Validating the configuration");

            lock (syncLock)
            {
                try
                {
                    isValid = true;

                    //TODO: is there a better way to do this?
                    var navigator = configSectionNode.CreateNavigator();
                    var doc = new XmlDocument();
                    doc.LoadXml(navigator.OuterXml);
                    doc.Schemas.Add(Schema);
                    doc.Validate(ValidationCallback);

                    if (isValid)
                    {
                        log.Debug("The configuration is valid");
                    }
                    else
                    {
                        log.Error("The configuration is invalid");
                    }
                }
                catch (XmlException ex)
                {
                    log.Error("An error occurred when validating the configuration", ex);
                    isValid = false;
                }

                return isValid ? Domain.ErrorCode.Ok : Domain.ErrorCode.InvalidConfig;
            }
        }
开发者ID:binarymash,项目名称:DatabaseScripter,代码行数:35,代码来源:ConfigurationValidator.cs

示例7: ValidaXml

        /// <summary>
        /// 	Valida uno stream XML dal tuo schema XSD
        /// </summary>
        /// <param name = "avviso"></param>
        /// <param name = "fileStream">Stream XML</param>
        /// <param name = "xsdFilePath">Schema XSD</param>
        /// <returns></returns>
        public static bool ValidaXml(out string avviso, Stream fileStream, string xsdFilePath)
        {
            _xmlValido = true;

            using (fileStream)
            {
                try
                {
                    var document = new XmlDocument();
                    document.PreserveWhitespace = true;
                    document.Schemas.Add(null, xsdFilePath);
                    document.Load(fileStream);
                    document.Validate(ValidationCallBack);
                }
                catch (Exception ex)
                {
                    avviso = ex.Message;
                    _xmlValido = false;
                    return _xmlValido;
                }

                avviso = _avviso;
                return _xmlValido;
            }
        }
开发者ID:bertasoft,项目名称:Common,代码行数:32,代码来源:XmlValidator.cs

示例8: XmlLoader

        /// <summary>
        /// Initializes the mission and vilidates the mission file with mission XMLSchema file.
        /// </summary>
        /// <param name="missionFilePath">The path to the file with mission.</param>
        /// <param name="teams">The dictionary which will be filled by Teams (should be empty).</param>
        /// <param name="solarSystems">The dictionary which will be filled by SolarSystem. (should be empty).</param>
        public XmlLoader(string missionFilePath, Dictionary<string, Team> teams,
			List<SolarSystem> solarSystems)
        {
            loadedMovements = new Dictionary<string, string>();
            loadedOccupations = new List<Tuple<List<string>, string, int>>();
            loadedFights = new List<Tuple<List<string>, List<string>>>();
            teamRealationDict = new Dictionary<Team, List<Team>>();

            this.teamDict = teams;
            this.solarSystemList = solarSystems;
            xml = new XmlDocument();

            // Checks the mission XmlSchema
            XmlSchemaSet schemas = new XmlSchemaSet();
            schemas.Add("", schemaPath);

            xml.Load(missionFilePath);
            xml.Schemas.Add(schemas);
            string msg = "";
            xml.Validate((o, err) => {
                msg = err.Message;
            });

            if (msg == "") {
                Console.WriteLine("Document is valid");
            } else {
                throw new XmlLoadException("Document invalid: " + msg);
            }
            root = xml.DocumentElement;

            runtimeCtor = new RunTimeCreator();
        }
开发者ID:vavrekmichal,项目名称:StrategyGame,代码行数:38,代码来源:XmlLoader.cs

示例9: ValidategbXML_601

 /// <summary>
 /// Validate gbxml file against the 6.01 schema XSD
 /// </summary>
 private void ValidategbXML_601()
 {
     XmlDocument xml = new XmlDocument();
     xml.Load(@"data/TestgbXML.xml");
     xml.Schemas.Add(null, @"data/GreenBuildingXML_Ver6.01.xsd");
     ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
     xml.Validate(eventHandler);
 }
开发者ID:Carmelsoft,项目名称:GenericgbXMLValidator_601,代码行数:11,代码来源:TestForm.cs

示例10: Validate

    public static void Validate(XmlDocument message)
    {
      string errMsgs = string.Empty;

      message.Validate((sender, args) => { errMsgs += args.Message; });

      if (!string.IsNullOrEmpty(errMsgs))
        throw new ArgumentOutOfRangeException(errMsgs);
    }
开发者ID:AndyTempel,项目名称:SLOTax,代码行数:9,代码来源:XmlHelperFunctions.cs

示例11: Validate

        /// <summary>
        /// Validate the given XML against the schema.
        /// </summary>
        /// <param name="xmlDocument">An <see cref="XmlDocument"/>. The XML to validate.</param>
        /// <param name="schemas">An <see cref="XmlSchemaSet"/>. The schema to validate with.</param>
        public static void Validate(XmlDocument xmlDocument, XmlSchemaSet schemas)
        {
            if (xmlDocument == null)
            {
                throw new ArgumentNullException("xmlDocument");
            }

            xmlDocument.Schemas = schemas;
            xmlDocument.Validate(null);
        }
开发者ID:StealFocus,项目名称:Core,代码行数:15,代码来源:XmlValidator.cs

示例12: ValidateXML

 private void ValidateXML(XmlDocument inputXmlDocument)
 {
     inputXmlDocument.Schemas.Add("", new XmlTextReader(new StringReader(Resources.XmlServerReport)));
     inputXmlDocument.Validate(
         (o, e) =>
         {
             throw new CruiseControlRepositoryException(
                 "Invalid XML data. Does not validate against the schema", e.Exception);
         });
     inputXmlDocument.Schemas = null;
 }
开发者ID:ArildF,项目名称:Smeedee,代码行数:11,代码来源:XmlServerReportParser.cs

示例13: ValidateXML

		public void ValidateXML ()
		{			      
			XmlReader reader = XmlReader.Create ("MyModels.xml");     
			XmlDocument document = new XmlDocument ();     

			document.Schemas.Add ("", "MyModels.xsd");     
			document.Load (reader);     

			document.Validate (new 
				ValidationEventHandler (ValidationEventHandler)); 
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:11,代码来源:VAlidateXML.cs

示例14: CheckSchemaValidation

        /// <summary>
        /// Checks the schema validation.
        /// </summary>
        /// <param name="xml">The XML.</param>
        private static void CheckSchemaValidation(string xml)
        {
            var document = new XmlDocument();

            document.Schemas.Add("http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection",
                XmlReader.Create("IgniteConfigurationSection.xsd"));

            document.Load(new StringReader(xml));

            document.Validate(null);
        }
开发者ID:RazmikMkrtchyan,项目名称:ignite,代码行数:15,代码来源:SchemaTest.cs

示例15: ValidateXML

        public void ValidateXML(string xmlPath)
        {
            string xsdPath = @"Resources\person.xsd";
            Console.WriteLine("Validating " + xmlPath);

            XmlReader reader = XmlReader.Create(xmlPath);
            XmlDocument document = new XmlDocument();
            document.Schemas.Add("", xsdPath);
            document.Load(reader);
            document.Validate(ValidationEventHandler);
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:11,代码来源:Listing_3_16.cs


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