Exemple #1
0
        public IModuleInfo[] Parse(string xml)
        {
            SolutionProfileElement solution = XmlValidationHelper.DeserializeXml <SolutionProfileV2.SolutionProfileElement>(xml,
                                                                                                                            "SolutionProfileV2.xsd", Namespace);

            List <DependentModuleInfo> dmis = new List <DependentModuleInfo>();

            if (solution.Section != null)
            {
                foreach (SectionElement section in solution.Section)
                {
                    foreach (ModuleInfoElement moduleInfo in section.Modules)
                    {
                        DependentModuleInfo dmi = new DependentModuleInfo(moduleInfo.AssemblyFile);
                        SetModuleName(moduleInfo, dmi);
                        SetModuleRoles(moduleInfo, dmi);
                        SetSectionDependencies(solution.Section, section, dmi);
                        SetModuleDependencies(moduleInfo, dmi);
                        dmis.Add(dmi);
                    }
                }
            }

            return(dmis.ToArray());
        }
        public void XmlValidationFailedTest()
        {
            const string XmlFileName = @"..\..\AccipioTests\AccipioActionsIncorrectXml.xml";
            const string XsdFileName = @"..\..\..\Accipio.Console\AccipioActions.xsd";

            XmlValidationHelper xmlValidationHelper = new XmlValidationHelper();

            xmlValidationHelper.ValidateXmlDocument(XmlFileName, XsdFileName);
        }
        public void XmlValidationWithSchemaTest()
        {
            const string XmlFileName = "../../AccipioTests/Samples/OnlineBankingBusinessActions.xml";
            const string XsdFileName = @"..\..\..\Accipio.Console\AccipioActions.xsd";

            XmlValidationHelper xmlValidationHelper = new XmlValidationHelper();

            xmlValidationHelper.ValidateXmlDocument(XmlFileName, XsdFileName);
        }
        public IModuleInfo[] Parse(string xml)
        {
            SolutionProfileElement solution = XmlValidationHelper.DeserializeXml <SolutionProfileV1.SolutionProfileElement>(xml,
                                                                                                                            "SolutionProfileV1.xsd", Namespace);

            List <ModuleInfo> mis = new List <ModuleInfo>();

            if (solution.Modules != null)
            {
                foreach (ModuleInfoElement moduleInfo in solution.Modules)
                {
                    ModuleInfo mi = new ModuleInfo(moduleInfo.AssemblyFile);
                    SetModuleRoles(moduleInfo, mi);
                    mis.Add(mi);
                }
            }

            return(mis.ToArray());
        }
Exemple #5
0
        private void AssertTestSuiteXmlFileValidity(bool shouldBeValid)
        {
            try
            {
                // first generate the schema
                TestSuiteSchemaGeneratorCommand cmd = new TestSuiteSchemaGeneratorCommand();
                string[] arguments = new string[] { "-ba=" + BusinessActionsXmlFile, "-ns=http://fikus" };

                Assert.AreEqual(0, cmd.Execute(arguments));

                // now validate our test suite with the generated schema
                XmlValidationHelper helper = new XmlValidationHelper();
                helper.ValidateXmlDocument(TestSuiteXmlFile, cmd.TestSuiteSchemaFileName);
                Assert.IsTrue(shouldBeValid);
            }
            catch (XmlSchemaException ex)
            {
                Assert.IsFalse(shouldBeValid, "Validation failed: '{0}'", ex.Message);
            }
        }
        public static void Main()
        {
            var errors = 0;
            var xsd    =
                @"<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
	<xsd:element name='Root'>
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name='Child1' minOccurs='1' maxOccurs='1'/>
				<xsd:element name='Child2' minOccurs='1' maxOccurs='1'>
					<xsd:complexType>
						<xsd:simpleContent>
							<xsd:extension base='xsd:string'>
								<xsd:attribute name='Att1' default='Att1 Default Value'/>
							</xsd:extension>
						</xsd:simpleContent>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>"
            ;
            XDocument xd = new XDocument
                           (
                new XElement
                (
                    "Root",
                    new XElement("Child1", "c1"),
                    new XElement("Child3", "c2"),
                    new XElement("Child1", "c1"),
                    new XElement("Child3", "c2"),
                    new XElement("Child3", "data3"),
                    new XElement("Child2", "data4"),
                    new XElement("Info5", "info5"),
                    new XElement("Info6", "info6"),
                    new XElement("Info7", "info7"),
                    new XElement("Info8", "info8")
                )
                           );
            var r = XmlValidationHelper.XsdValidateXml
                    (
                xd
                , ""
                , xsd
                , out errors
                //, (x, y) =>
                //{
                //	Console.WriteLine("{0}", y.Exception);
                //}
                    );

            Console.WriteLine("============== XsdValidateXml By XDocument {0}, {1} errors", r, errors);
            r = XmlValidationHelper.XsdValidateXml
                (
                xd
                , ""
                , xsd
                , out errors
                , (x, y) =>
            {
                Console.WriteLine("{0}", y.Exception);
            }
                );
            Console.WriteLine("============== XsdValidateXml By XDocument {0}, {1} errors", r, errors);
            Console.WriteLine("==========================================================================");
            var xml = xd.ToString();

            r = XmlValidationHelper.XsdValidateXml
                (
                xml
                , null     //"http://www.contoso.com/books"
                , xsd
                , out errors
                , false
                , (x, y) =>
            {
                Console.WriteLine("***Validation error");
                Console.WriteLine("\tSeverity:{0}", y.Severity);
                Console.WriteLine("\tMessage  :{0}", y.Message);
            }
                , (x) =>
            {
                Console.WriteLine("{0}", x);
                return(false);
            }
                );
            Console.WriteLine("============== XsdValidateXml By Xml(XmlReader) {0}, {1} errors", r, errors);
            Console.WriteLine("==========================================================================");
            Console.WriteLine("press any key to continue ...");
            Console.ReadLine();
            xml =
                @"<bookstore>
	<book genre=""autobiography"" publicationdate=""1981"" ISBN=""1-861003-11-0"">
		<title>The Autobiography of Benjamin Franklin</title>
			<author>
				<first-name>Benjamin</first-name>
				<last-name>Franklin</last-name>
			</author>
			<price>8.99</price>
	</book>
	<book publicationdate=""1967"" ISBN=""0-201-63361-2"">
		<title>The Confidence Man</title>
		<author>
			<first-name>Herman</first-name>
			<last-name>Melville</last-name>
		</author>
		<price>11.99</price>
	</book>
	<book publicationdate=""1991"" ISBN=""1-861001-57-6"">
		<title>The Gorgias</title>
		<author>
			<name>Plato</name>
		</author>
		<price>9.99</price>
	</book>
</bookstore>
";
            xsd =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<xs:schema attributeFormDefault=""unqualified"" elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<!-- <xs:schema attributeFormDefault=""unqualified"" elementFormDefault=""qualified"" targetNamespace=""http://www.contoso.com/books"" xmlns:xs=""http://www.w3.org/2001/XMLSchema""> -->
	<xs:element name=""bookstore"">
		<xs:complexType>
			<xs:sequence>
				<xs:element maxOccurs=""unbounded"" name=""book"">
					<xs:complexType>
						<xs:sequence>
							<xs:element name=""title"" type=""xs:string"" />
							<xs:element name=""author"">
								<xs:complexType>
									<xs:sequence>
										<xs:element minOccurs=""0"" name=""name"" type=""xs:string"" />
										<xs:element minOccurs=""0"" name=""first-name"" type=""xs:string"" />
										<xs:element minOccurs=""0"" name=""last-name"" type=""xs:string"" />
									</xs:sequence>
								</xs:complexType>
							</xs:element>
							<xs:element name=""price"" type=""xs:decimal"" />
						</xs:sequence>
						<xs:attribute name=""genre"" type=""xs:string"" use=""required"" />
						<xs:attribute name=""publicationdate"" type=""xs:unsignedShort"" use=""required"" />
						<xs:attribute name=""ISBN"" type=""xs:string"" use=""required"" />
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
";
            r = XmlValidationHelper.XsdValidateXml
                (
                xml
                , null     //"http://www.contoso.com/books"
                , xsd
                , out errors
                //, (x, y) =>
                //{
                //	Console.WriteLine("***Validation error");
                //	Console.WriteLine("\tSeverity:{0}", y.Severity);
                //	Console.WriteLine("\tMessage  :{0}", y.Message);
                //}
                //, (x) =>
                //{
                //	Console.WriteLine("{0}", x);
                //	return false;
                //}
                //, true
                );
            Console.WriteLine("============== XsdValidateXml By Xml(XmlReader) {0}, {1} errors", r, errors);
            r = XmlValidationHelper.XsdValidateXml
                (
                xml
                , null     //"http://www.contoso.com/books"
                , xsd
                , out errors
                , true
                , (x, y) =>
            {
                Console.WriteLine("***Validation error");
                Console.WriteLine("\tSeverity:{0}", y.Severity);
                Console.WriteLine("\tMessage  :{0}", y.Message);
            }
                , (x) =>
            {
                Console.WriteLine("{0}", x);
                return(false);
            }
                , (x) =>
            {
                Console.WriteLine("{0}", x);
                return(false);
            }
                , (x) =>
            {
                Console.WriteLine("{0}", x);
                return(false);
            }
                );
            Console.WriteLine("============== XsdValidateXml By Xml(XmlReader) {0}, {1} errors", r, errors);
            Console.WriteLine("==========================================================================");
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);
            r = XmlValidationHelper.XsdValidateXml
                (
                xmlDocument
                , ""         //"http://www.contoso.com/books"
                , xsd
                , out errors
                //, (x, y) =>
                //{
                //	Console.WriteLine("***Validation error");
                //	Console.WriteLine("\tSeverity:{0}", y.Severity);
                //	Console.WriteLine("\tException  :{0}", y.Exception);
                //}
                );
            Console.WriteLine("============== XsdValidateXml By XmlDocument {0}, {1} errors", r, errors);
            r = XmlValidationHelper.XsdValidateXml
                (
                xmlDocument
                , ""         //"http://www.contoso.com/books"
                , xsd
                , out errors
                , (x, y) =>
            {
                Console.WriteLine("***Validation error");
                Console.WriteLine("\tSeverity:{0}", y.Severity);
                Console.WriteLine("\tException  :{0}", y.Exception);
            }
                );
            Console.WriteLine("============== XsdValidateXml By XmlDocument {0}, {1} errors", r, errors);
            Console.WriteLine("==========================================================================");
            Console.WriteLine("Validation finished");
            Console.ReadLine();
        }