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


C# XDocument.Validate方法代码示例

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


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

示例1: GetXml

        public string GetXml(bool validate)
        {
            XNamespace ns = "http://sd.ic.gc.ca/SLDR_Schema_Definition_en";

            var spectrum_licences = getLicences();

            XDocument doc = new XDocument(new XElement("spectrum_licence_data_registry", spectrum_licences));

            foreach (XElement e in doc.Root.DescendantsAndSelf())
            {
                if (e.Name.Namespace == "")
                    e.Name = ns + e.Name.LocalName;
            }

            var errors = new StringBuilder();

            if (validate)
            {
                XmlSchemaSet set = new XmlSchemaSet();
                var schema = getMainSchema();
                set.Add(null, schema);

                doc.Validate(set, (sender, args) => { errors.AppendLine(args.Message); });
            }

            //return errors.Length > 0 ? errors.ToString() : doc.ToString();
            var  result = errors.Length > 0 ? "Validation Errors: " + errors.ToString() : getDocumentAsString(doc);
            return result;
        }
开发者ID:mathewvance,项目名称:Silo,代码行数:29,代码来源:SldrTechnicalDataService.cs

示例2: Parse

        public List<EndpointInstance> Parse(XDocument document)
        {
            document.Validate(schema, null, true);

            var root = document.Root;
            var endpointElements = root.Descendants("endpoint");

            var instances = new List<EndpointInstance>();

            foreach (var e in endpointElements)
            {
                var endpointName = e.Attribute("name").Value;

                foreach (var i in e.Descendants("instance"))
                {
                    var discriminatorAttribute = i.Attribute("discriminator");
                    var discriminator = discriminatorAttribute?.Value;

                    var properties = i.Attributes().Where(a => a.Name != "discriminator");
                    var propertyDictionary = properties.ToDictionary(a => a.Name.LocalName, a => a.Value);

                    instances.Add(new EndpointInstance(endpointName, discriminator, propertyDictionary));
                }
            }

            return instances;
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:27,代码来源:InstanceMappingFileParser.cs

示例3: DDEX

        public DDEX(XDocument doc, bool verifySchema = false)
        {
            if (verifySchema)
                doc.Validate(DDEXSchema.GetDdexSchema(), null);

            Root = new NewReleaseMessage(doc.Root);
        }
开发者ID:Grendel,项目名称:DDEX-Deserialiser,代码行数:7,代码来源:DDEX.cs

示例4: Validate

    private static void Validate(XDocument doc, XmlSchemaSet xmlScheme)
    {
        bool notValidated = false;
        doc.Validate(xmlScheme, (eventObject, eventHandler) => { notValidated = true; }, false);

        Console.WriteLine(notValidated ? "Not Validated" : "Validated");
    }
开发者ID:YavorIT,项目名称:DatabaseOnlineCourseTelerikHW,代码行数:7,代码来源:ValidateXMLToAScheme.cs

示例5: IsValidMessage

        internal static bool IsValidMessage(XDocument doc, XDocument schema)
        {
            var schemas = new XmlSchemaSet();

            schemas.Add("http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message",
                GetPath("lib\\SDMXMessage.xsd"));


            if (schema != null)
            {
                using (var reader = schema.CreateReader())
                {
                    schemas.Add(null, reader);
                }
            }

            bool isValid = true;

            doc.Validate(schemas, (s, args) =>
            {
                isValid = false;
                if (args.Severity == XmlSeverityType.Warning)

                    Console.WriteLine("\tWarning: " + args.Message);
                else
                    Console.WriteLine("\tError: " + args.Message);
            });

            return isValid;
        }
开发者ID:dur41d,项目名称:sdmxdotnet,代码行数:30,代码来源:Utility.cs

示例6: ValidateSchema

 private static void ValidateSchema(XDocument doc, XmlSchemaSet schema, string file)
 {
     doc.Validate(schema, (obj, ev) =>
     {
         Console.WriteLine("{0} --> {1}", file, ev.Message);
     });
 }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:7,代码来源:Program.cs

示例7: ValidateSchema

 private static void ValidateSchema(XDocument doc, XmlSchemaSet schema, string file)
 {
     doc.Validate(schema, (o, e) =>
     {
         Console.WriteLine("Not valid schema in file \"{0}\"\nException: {1}", file, e.Message);
     });
 }
开发者ID:danisio,项目名称:Databases-Homeworks,代码行数:7,代码来源:ValidationSchema.cs

示例8: Normalize

 public static XDocument Normalize(XDocument source, XmlSchemaSet schema)
 {
     bool havePSVI = false;
     // validate, throw errors, add PSVI information
     if (schema != null)
     {
         source.Validate(schema, null, true);
         havePSVI = true;
     }
     return new XDocument(
         source.Declaration,
         source.Nodes().Select(n =>
         {
             // Remove comments, processing instructions, and text nodes that are
             // children of XDocument.  Only white space text nodes are allowed as
             // children of a document, so we can remove all text nodes.
             if (n is XComment || n is XProcessingInstruction || n is XText)
                 return null;
             XElement e = n as XElement;
             if (e != null)
                 return NormalizeElement(e, havePSVI);
             return n;
         }
         )
     );
 }
开发者ID:mvlasenko,项目名称:TridionDesktopTools,代码行数:26,代码来源:MarkupSimplifier.cs

示例9: Validate

        /// <summary>
        /// Validates Xml against the configured schema and outs validation erros if any
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="validationErrors"></param>
        /// <returns></returns>
        public bool Validate(XDocument xmlDoc, out string validationErrors)
        {

            validationErrors = null;

            //This will contain the xml schema
            var schemas = new XmlSchemaSet();

            //Add the schema, targetNamespace not specified
            schemas.Add(_xmlNamespace, XmlReader.Create(new StringReader(_xsdDoc)));

            //Variable to check if there are errors
            var hasValidationErrors = false;
            string xmlValidationErrorMessage = null;
            //Validate the xml against the schema
            xmlDoc.Validate(schemas, (sender, eventArgs) =>
                                         {
                                             hasValidationErrors = true;
                                             xmlValidationErrorMessage = eventArgs.Message;
                                         });

            validationErrors = xmlValidationErrorMessage;

            // validation fails if validation errors
            return !hasValidationErrors;

        }
开发者ID:OfficeDev,项目名称:Office-IT-Pro-Deployment-Scripts,代码行数:33,代码来源:XmlValidator.cs

示例10: PrintValidationResult

 private static void PrintValidationResult(XDocument doc, XmlSchemaSet schema, string file)
 {
     doc.Validate(schema, (obj, ev) =>
     {
         Console.WriteLine("* {0} * {1}",file, ev.Message);
     });
 }
开发者ID:zondario,项目名称:TelerikAcademy-Homeworks,代码行数:7,代码来源:Program.cs

示例11: PrintValidationResult

 private static void PrintValidationResult(XDocument doc, XmlSchemaSet schema, string file)
 {
     doc.Validate(schema, (obj, ev) =>
     {
         Console.WriteLine("!!! SCHEME VALIDATION ERROR IN FILE ---> {0} !!! {1}", file, ev.Message);
     });
 }
开发者ID:InKolev,项目名称:TelerikAcademy,代码行数:7,代码来源:Program.cs

示例12: ValidateSave

        public void ValidateSave()
        {
            WorldEntity world = createTestWorld();

            XElement xElement = WorldTransformer.Instance.ToXElement(world, TransformerSettings.WorldNamespace + "World");

            xElement.Save("unittestsave.xml", SaveOptions.OmitDuplicateNamespaces);

            XmlSchemaSet schemaSet = new XmlSchemaSet();

            schemaSet.Add(null, "WorldSchema1.xsd");

            XDocument xDocument = new XDocument(xElement);
            xDocument.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
            xDocument.Save("unittest2.xml", SaveOptions.OmitDuplicateNamespaces);

            XElement x1 = new XElement(TransformerSettings.WorldNamespace + "Outer");
            x1.Add(new XElement(TransformerSettings.WorldNamespace + "Inner"));
            x1.Save("unittest3.xml", SaveOptions.OmitDuplicateNamespaces);
            string val = "";
            xDocument.Validate(schemaSet, (o, vea) => {
                val += o.GetType().Name + "\n";
                val += vea.Message + "\n";
            }, true);

            Assert.AreEqual("", val);
        }
开发者ID:neaket,项目名称:Dragonfly,代码行数:27,代码来源:WorldTests.cs

示例13: ValidateXml

 private static void ValidateXml(XDocument document, XmlSchemaSet schema)
 {
     document.Validate(schema, (obj, ev) =>
         {
             Console.WriteLine("{0}", ev.Message);
         });
 }
开发者ID:antonpopov,项目名称:Databases,代码行数:7,代码来源:Program.cs

示例14: IsValid

        public bool IsValid(XDocument doc, XDocument schema, string xmlns = "")
        {
            var isValid = true;

            if (string.IsNullOrEmpty(xmlns))
            {
                xmlns = GetXmlnsFromSchema(schema);
            }

            // 1. Verify that the document has a namespace
            if (!string.IsNullOrEmpty(xmlns) && string.IsNullOrEmpty(GetXmlnsFromDocument(doc)))
            {
                return false;
            }

            // 2. Validate against schema
            var schemas = new XmlSchemaSet();
            schemas.Add(xmlns, XmlReader.Create(new StringReader(schema.ToString())));
            doc.Validate(schemas, (sender, args) =>
                                      {
                                          isValid = false;
                                      }, true);

            return isValid;
        }
开发者ID:aharita,项目名称:XmlSchemaValidator,代码行数:25,代码来源:XmlSchemaValidator.cs

示例15: IsValidTwiML

		public bool IsValidTwiML(XDocument doc)
		{
			Console.Write(doc.ToString());

			var valid = true;
			doc.Validate(Schemas, (o, e) => { valid = false; });
			return valid;
		}
开发者ID:vmhung93,项目名称:twilio-csharp,代码行数:8,代码来源:TestBase.cs


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