Compile() private method

private Compile ( ValidationEventHandler, validationEventHandler ) : void
validationEventHandler ValidationEventHandler,
return void
コード例 #1
0
        public void TestAdd()
        {
            XmlSchemaCollection col    = new XmlSchemaCollection();
            XmlSchema           schema = new XmlSchema();
            XmlSchemaElement    elem   = new XmlSchemaElement();

            elem.Name = "foo";
            schema.Items.Add(elem);
            schema.TargetNamespace = "urn:foo";
            col.Add(schema);
            col.Add(schema);                    // No problem !?

            XmlSchema schema2 = new XmlSchema();

            schema2.Items.Add(elem);
            schema2.TargetNamespace = "urn:foo";
            col.Add(schema2);                   // No problem !!

            schema.Compile(null);
            col.Add(schema);
            col.Add(schema);                    // Still no problem !!!

            schema2.Compile(null);
            col.Add(schema2);

            schema = GetSchema("Test/XmlFiles/xsd/3.xsd");
            schema.Compile(null);
            col.Add(schema);

            schema2 = GetSchema("Test/XmlFiles/xsd/3.xsd");
            schema2.Compile(null);
            col.Add(schema2);
        }
コード例 #2
0
        [Test]         // bug #502115
        public void ExtensionRedefineAttribute1()
        {
            const string xml = "<Bar xmlns='foo'/>";

            XmlSchema schema = GetSchema("Test/XmlFiles/xsd/extension-attr-redefine-1.xsd");

#if NET_2_0
            XmlSchemaSet xss = new XmlSchemaSet();
            xss.Add(schema);
            if (StrictMsCompliant)
            {
                xss.Compile();
            }
            else
            {
                try {
                    xss.Compile();
                    Assert.Fail();
                } catch (XmlSchemaException) {
                }
                return;
            }

            StringReader sr = new StringReader(xml);

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas        = xss;
            XmlReader vr = XmlReader.Create(sr, settings);
#else
            if (StrictMsCompliant)
            {
                schema.Compile(null);
            }
            else
            {
                try {
                    schema.Compile(null);
                    Assert.Fail();
                } catch (XmlSchemaException) {
                }
                return;
            }

            XmlValidatingReader vr = new XmlValidatingReader(xml,
                                                             XmlNodeType.Document, null);
            vr.Schemas.Add(schema);
            vr.ValidationType = ValidationType.Schema;
#endif

            try {
                vr.Read();
                Assert.Fail();
            } catch (XmlSchemaException) {
            }
        }
コード例 #3
0
        /* Takes a type name, and a valid example of that type,
         * Creates a schema consisting of a single element of that
         * type, and validates a bit of xml containing the valid
         * value, with whitespace against that schema.
         *
         * FIXME: Really we want to test the value of whitespace more
         * directly that by creating a schema then parsing a string.
         *
         */

        public void WhiteSpaceTest(string type, string valid)
        {
            passed = true;
            XmlSchema schema = new XmlSchema();

            schema.TargetNamespace = "http://example.com/testCase";
            XmlSchemaElement element = new XmlSchemaElement();

            element.Name           = "a";
            element.SchemaTypeName = new XmlQualifiedName(type, "http://www.w3.org/2001/XMLSchema");
            schema.Items.Add(element);
            schema.Compile(new ValidationEventHandler(ValidationCallbackOne));

            XmlValidatingReader vr = new XmlValidatingReader(new XmlTextReader(new StringReader("<a xmlns='http://example.com/testCase'>\n\n" + valid + "\n\n</a>")));

            vr.Schemas.Add(schema);
            vr.ValidationType = ValidationType.Schema;
//      vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
            while (vr.Read())
            {
            }
            ;
            vr.Close();

            Assert.IsTrue(passed, type + " doesn't collapse whitespace: " + (errorInfo != null ? errorInfo.Message : null));
        }
コード例 #4
0
    void GenerateXmlSchema(String[] formats, String fileFormatType)
    {
        StreamWriter         writer = File.CreateText(xmlSchemaFile + "_" + fileFormatType + ".xml");
        XmlSchema            schema;
        XmlSchemaElement     element;
        XmlSchemaComplexType complexType;
        XmlSchemaSequence    sequence;

        schema  = new XmlSchema();
        element = new XmlSchemaElement();
        schema.Items.Add(element);
        element.Name         = "Table";
        complexType          = new XmlSchemaComplexType();
        element.SchemaType   = complexType;
        sequence             = new XmlSchemaSequence();
        complexType.Particle = sequence;
        element                = new XmlSchemaElement();
        element.Name           = "Number";
        element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        sequence.Items.Add(element);
        for (int i = 0; i < formats.Length; i++)
        {
            element                = new XmlSchemaElement();
            element.Name           = formats[i];
            element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
            sequence.Items.Add(element);
        }
        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
        schema.Write(writer);
        writer.Close();
    }
コード例 #5
0
        private void LoadSchemes()
        {
            string schemaDir = Path.GetFullPath(".\\schemas\\");

            if (Directory.Exists(schemaDir))
            {
                string[] schemas = Directory.GetFiles(schemaDir, "*.xsd", SearchOption.TopDirectoryOnly);
                foreach (var schemaPath in schemas)
                {
                    //Load
                    try
                    {
                        using (TextReader reader = File.OpenText(schemaPath))
                        {
                            XmlSchema schema = XmlSchema.Read(reader, XmppSchemeValidationEventHandler);
                            if (!schemaSet.ContainsKey(schema.TargetNamespace))
                            {
#pragma warning disable 618,612
                                schema.Compile(XmppSchemeValidationEventHandler);
#pragma warning restore 618,612
                                schemaSet.Add(schema.TargetNamespace, schema);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        log.ErrorFormat("error loading scheme {0}", schemaPath);
                    }
                }
            }
        }
コード例 #6
0
        [Test]         // bug #502115
        public void ExtensionRedefineAttribute2()
        {
            const string xml = "<Bar xmlns='foo'/>";

            XmlSchema schema = GetSchema("Test/XmlFiles/xsd/extension-attr-redefine-2.xsd");

#if NET_2_0
            XmlSchemaSet xss = new XmlSchemaSet();
            xss.Add(schema);
            xss.Compile();

            StringReader sr = new StringReader(xml);

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas        = xss;
            XmlReader vr = XmlReader.Create(sr, settings);
#else
            schema.Compile(null);

            XmlValidatingReader vr = new XmlValidatingReader(xml,
                                                             XmlNodeType.Document, null);
            vr.Schemas.Add(schema);
            vr.ValidationType = ValidationType.Schema;
#endif

            while (vr.Read())
            {
                ;
            }
        }
コード例 #7
0
        /// <summary>
        /// Generates strongly typed serialization classes for the given schema document
        /// under the given namespace and generates a code compile unit.
        /// </summary>
        /// <param name="xmlSchema">Schema document to generate classes for.</param>
        /// <param name="generateNamespace">Namespace to be used for the generated code.</param>
        /// <returns>A fully populated CodeCompileUnit, which can be serialized in the language of choice.</returns>
        public static CodeCompileUnit Generate(XmlSchema xmlSchema, string generateNamespace)
        {
            if (xmlSchema == null)
            {
                throw new ArgumentNullException("xmlSchema");
            }
            if (generateNamespace == null)
            {
                throw new ArgumentNullException("generateNamespace");
            }

            simpleTypeNamesToClrTypeNames = new Hashtable();
            typeNamesToEnumDeclarations   = new Hashtable();

            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
            CodeNamespace   codeNamespace   = new CodeNamespace(generateNamespace);

            codeCompileUnit.Namespaces.Add(codeNamespace);
            codeNamespace.Imports.Add(new CodeNamespaceImport("System"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Collections"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Xml"));

            simpleTypeNamesToClrTypeNames.Add("dateTime", "DateTime");
            simpleTypeNamesToClrTypeNames.Add("uint", "uint");
            simpleTypeNamesToClrTypeNames.Add("int", "int");
            simpleTypeNamesToClrTypeNames.Add("integer", "int");
            simpleTypeNamesToClrTypeNames.Add("NMTOKEN", "string");
            simpleTypeNamesToClrTypeNames.Add("nonNegativeInteger", "uint");
            simpleTypeNamesToClrTypeNames.Add("string", "string");

            xmlSchema.Compile(null);

            foreach (XmlSchemaObject schemaObject in xmlSchema.SchemaTypes.Values)
            {
                XmlSchemaComplexType schemaComplexType = schemaObject as XmlSchemaComplexType;
                if (schemaComplexType != null)
                {
                    ProcessComplexType(schemaComplexType, codeNamespace);
                }

                XmlSchemaSimpleType schemaSimpleType = schemaObject as XmlSchemaSimpleType;
                if (schemaSimpleType != null)
                {
                    ProcessSimpleType(schemaSimpleType, codeNamespace);
                }
            }

            foreach (XmlSchemaObject schemaObject in xmlSchema.Elements.Values)
            {
                XmlSchemaElement schemaElement = schemaObject as XmlSchemaElement;
                if (schemaElement != null)
                {
                    ProcessElement(schemaElement, codeNamespace);
                }
            }

            return(codeCompileUnit);
        }
コード例 #8
0
        public void VerifyThatReferencedSchemaCanBeLoaded()
        {
            var a      = Assembly.GetExecutingAssembly();
            var stream = a.GetManifestResourceStream("ReqIFSharp.Tests.driver.xsd");

            XmlSchema schema = XmlSchema.Read(stream, this.ValidationEventHandler);

            schema.Compile(this.ValidationEventHandler, new ReqIfSchemaResolver());
        }
コード例 #9
0
ファイル: xs-psci-compare.cs プロジェクト: pmq20/mono_forked
	public void DumpSchema (XmlSchema schema)
	{
		schema.Compile (null);

		SortedList sl = new SortedList ();

		IndentLine ("**XmlSchema**");
		IndentLine ("TargetNamespace: " + schema.TargetNamespace);
		IndentLine ("AttributeGroups:");
		foreach (DictionaryEntry entry in schema.AttributeGroups)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			DumpAttributeGroup ((XmlSchemaAttributeGroup) entry.Value);
		sl.Clear ();

		IndentLine ("Attributes:");
		foreach (DictionaryEntry entry in schema.Attributes)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			DumpAttribute ((XmlSchemaAttribute) entry.Value);
		sl.Clear ();

		IndentLine ("Elements:");
		foreach (DictionaryEntry entry in schema.Elements)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			DumpElement ((XmlSchemaElement) entry.Value);
		sl.Clear ();

		IndentLine ("Groups");
		foreach (DictionaryEntry entry in schema.Groups)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			DumpGroup ((XmlSchemaGroup) entry.Value);
		sl.Clear ();

		IndentLine ("IsCompiled: " + schema.IsCompiled);

		IndentLine ("Notations");
		foreach (DictionaryEntry entry in schema.Notations)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			DumpNotation ((XmlSchemaNotation) entry.Value);
		sl.Clear ();

		IndentLine ("SchemaTypes:");
		foreach (DictionaryEntry entry in schema.Notations)
			sl.Add (entry.Key.ToString (), entry.Value);
		foreach (DictionaryEntry entry in sl)
			if (entry.Value is XmlSchemaSimpleType)
				DumpSimpleType ((XmlSchemaSimpleType) entry.Value);
			else
				DumpComplexType ((XmlSchemaComplexType) entry.Value);
		sl.Clear ();

	}
コード例 #10
0
        public void TestCompile_ZeroLength_TargetNamespace()
        {
            XmlSchema schema = new XmlSchema();

            schema.TargetNamespace = string.Empty;
            Assert.IsTrue(!schema.IsCompiled);

            // MS.NET 1.x: The Namespace '' is an invalid URI.
            // MS.NET 2.0: The targetNamespace attribute cannot have empty string as its value.
            schema.Compile(null);
        }
コード例 #11
0
        private void LoadSchemas(out XmlSchema xsd, out XmlSchemas schemas)
        {
            using (FileStream fs = File.OpenRead(base.InputFilePath))
            {
                xsd = XmlSchema.Read(fs, null);
                xsd.Compile(null);
            }

            schemas = new XmlSchemas();
            schemas.Add(xsd);
        }
コード例 #12
0
        public void ThreeLevelNestedInclusion()
        {
            XmlTextReader r = new XmlTextReader("Test/XmlFiles/xsd/361818.xsd");

            try {
                XmlSchema xs = XmlSchema.Read(r, null);
                xs.Compile(null);
            } finally {
                r.Close();
            }
        }
コード例 #13
0
ファイル: MonoXSD.cs プロジェクト: raj581/Marvin
        /// <summary>
        ///     Writes a schema for each type in the assembly
        /// </summary>
        public void WriteSchema(string assembly, string lookup_type, string output_dir)
        {
            Assembly a;

            try {
                a = Assembly.LoadFrom(assembly);
            } catch (Exception e) {
                Console.WriteLine("Cannot use {0}, {1}", assembly, e.Message);
                return;
            }

            generatedSchemaTypes = new Hashtable();

            XmlSchemaType schemaType;

            foreach (Type t in a.GetTypes())
            {
                if (lookup_type != null && t.Name != lookup_type)
                {
                    continue;
                }

                try {
                    schemaType = WriteSchemaType(t);
                } catch (ArgumentException e) {
                    throw new ArgumentException(String.Format("Error: We cannot process {0}\n{1}", assembly, e.Message));
                }

                if (schemaType == null)
                {
                    continue;                     // skip
                }
                XmlSchemaElement schemaElement = WriteSchemaElement(t, schemaType);
                schema.Items.Add(schemaElement);
                schema.Items.Add(schemaType);
            }

            schema.ElementFormDefault = XmlSchemaForm.Qualified;
            schema.Compile(new ValidationEventHandler(OnSchemaValidation));

            string output = String.Format("schema{0}.xsd", fileCount);

            if (output_dir != null)
            {
                output = Path.Combine(output_dir, output);
            }

            XmlTextWriter writer = new XmlTextWriter(output, Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            schema.Write(writer);
            Console.WriteLine("\nWriting {0}.", output);
        }
コード例 #14
0
        // bug #77687
        public void CompileFillsSchemaPropertyInExternal()
        {
            string        schemaFileName = "Test/XmlFiles/xsd/77687.xsd";
            XmlTextReader tr             = new XmlTextReader(schemaFileName);

            XmlSchema        schema = XmlSchema.Read(tr, null);
            XmlSchemaInclude inc    = (XmlSchemaInclude)schema.Includes [0];

            Assert.IsNull(inc.Schema);
            schema.Compile(null);
            tr.Close();
            Assert.IsNotNull(inc.Schema);
        }
コード例 #15
0
        private static XmlSchema LoadSchema()
        {
            var schema = new XmlSchema();

            using (var stream = typeof(XmlCompletionDataProvider).Assembly.GetManifestResourceStream("Aras.Tools.InnovatorAdmin.Editor.xslt.xsd"))
            {
                using (var reader = XmlReader.Create(stream))
                {
                    schema = XmlSchema.Read(reader, new ValidationEventHandler(SchemaValidation));
                    schema.Compile(new ValidationEventHandler(SchemaValidation));
                }
            }
            return(schema);
        }
コード例 #16
0
        // Note that it could also apply to BaseTypeName (since if
        // it is xs:anyType and BaseType is empty, BaseTypeName
        // should be xs:anyType).
        public void TestAnyType()
        {
            XmlSchema schema = GetSchema("Test/XmlFiles/xsd/datatypesTest.xsd");

            schema.Compile(null);
            XmlSchemaElement     any   = schema.Elements [QName("e00", "urn:bar")] as XmlSchemaElement;
            XmlSchemaComplexType cType = any.ElementType as XmlSchemaComplexType;

            Assert.AreEqual(typeof(XmlSchemaComplexType), cType.GetType(), "#1");
            Assert.IsNotNull(cType, "#2");
            Assert.AreEqual(XmlQualifiedName.Empty, cType.QualifiedName, "#3");
            Assert.IsNull(cType.BaseSchemaType, "#4");               // In MS.NET 2.0 its null. In 1.1 it is not null.
            Assert.IsNotNull(cType.ContentTypeParticle, "#5");
        }
コード例 #17
0
        public void TestQualification()
        {
            XmlSchema schema = XmlSchema.Read(new XmlTextReader("Test/XmlFiles/xsd/5.xsd"), null);

            schema.Compile(null);
            XmlSchemaElement el = schema.Elements [QName("Foo", "urn:bar")] as XmlSchemaElement;

            Assert.IsNotNull(el);
            XmlSchemaComplexType ct  = el.ElementType as XmlSchemaComplexType;
            XmlSchemaSequence    seq = ct.ContentTypeParticle as XmlSchemaSequence;
            XmlSchemaElement     elp = seq.Items [0] as XmlSchemaElement;

            Assert.AreEqual(QName("Bar", ""), elp.QualifiedName);

            schema = XmlSchema.Read(new XmlTextReader("Test/XmlFiles/xsd/6.xsd"), null);
            schema.Compile(null);
            el = schema.Elements [QName("Foo", "urn:bar")] as XmlSchemaElement;
            Assert.IsNotNull(el);
            ct  = el.ElementType as XmlSchemaComplexType;
            seq = ct.ContentTypeParticle as XmlSchemaSequence;
            elp = seq.Items [0] as XmlSchemaElement;
            Assert.AreEqual(QName("Bar", "urn:bar"), elp.QualifiedName);
        }
コード例 #18
0
        public void TestReadFlags()
        {
            XmlSchema schema = GetSchema("Test/XmlFiles/xsd/2.xsd");

            schema.Compile(null);
            XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;

            Assert.IsNotNull(el);
            Assert.AreEqual(XmlSchemaDerivationMethod.Extension, el.Block);

            el = schema.Items [1] as XmlSchemaElement;
            Assert.IsNotNull(el);
            Assert.AreEqual(XmlSchemaDerivationMethod.Extension |
                            XmlSchemaDerivationMethod.Restriction, el.Block);
        }
コード例 #19
0
 /// <summary>
 /// Gets the apispec schema information.
 /// </summary>
 /// <returns>The XmlSchema instance containing the apispec schema information.</returns>
 public static XmlSchema GetApispecSchema()
 {
     if (apiSpecXsd == null)
     {
         //Load schema from resource file
         string[] ress = Assembly.GetExecutingAssembly().GetManifestResourceNames();
         if (ress == null || ress.Length != 1)
         {
             throw new ApplicationException("Assembly must be built with the apispec.xsd as embedded resource.");
         }
         Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ress[0]);
         apiSpecXsd = XmlSchema.Read(schemaStream, null);
         apiSpecXsd.Compile(null);
     }
     return(apiSpecXsd);
 }
コード例 #20
0
        public void TestSimpleImport()
        {
            XmlSchema schema = XmlSchema.Read(new XmlTextReader("Test/XmlFiles/xsd/3.xsd"), null);

            Assert.AreEqual("urn:foo", schema.TargetNamespace);
            XmlSchemaImport import = schema.Includes [0] as XmlSchemaImport;

            Assert.IsNotNull(import);

            schema.Compile(null);
            Assert.AreEqual(4, schema.Elements.Count);
            Assert.IsNotNull(schema.Elements [QName("Foo", "urn:foo")]);
            Assert.IsNotNull(schema.Elements [QName("Bar", "urn:foo")]);
            Assert.IsNotNull(schema.Elements [QName("Foo", "urn:bar")]);
            Assert.IsNotNull(schema.Elements [QName("Bar", "urn:bar")]);
        }
コード例 #21
0
ファイル: validate.cs プロジェクト: retahc/old-code
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                PrintUsage();
            }

            Stream s = null;

            switch (args[0])
            {
            case "ecma":
                s = Assembly.GetExecutingAssembly().GetManifestResourceStream("monodoc-ecma.xsd");
                break;

            default:
                Console.WriteLine("Unknown provider: {0}", args[0]);
                Environment.Exit(0);
                break;
            }

            if (s == null)
            {
                Console.WriteLine("ERROR: schema for {0} was not found", args[0]);
                Environment.Exit(1);
            }

            schema = XmlSchema.Read(s, null);
            schema.Compile(null);

            // skip args[0] because it is the provider name
            for (int i = 1; i < args.Length; i++)
            {
                string arg = args[i];
                if (IsMonodocFile(arg))
                {
                    ValidateFile(arg);
                }

                if (Directory.Exists(arg))
                {
                    RecurseDirectory(arg);
                }
            }

            Console.WriteLine("Total validation errors: {0}", errors);
        }
コード例 #22
0
        public void TestAll()
        {
            XmlSchema schema = GetSchema("Test/XmlFiles/xsd/datatypesTest.xsd");

            schema.Compile(null);

            AssertDatatype(schema, 1, XmlTokenizedType.CDATA, typeof(string), " f o o ", " f o o ");
            AssertDatatype(schema, 2, XmlTokenizedType.CDATA, typeof(string), " f o o ", " f o o ");
            // token shouldn't allow " f o o "
            AssertDatatype(schema, 3, XmlTokenizedType.CDATA, typeof(string), "f o o", "f o o");
            // language seems to be checked strictly
            AssertDatatype(schema, 4, XmlTokenizedType.CDATA, typeof(string), "x-foo", "x-foo");

            // NMTOKEN shouldn't allow " f o o "
//			AssertDatatype (schema, 5, XmlTokenizedType.NMTOKEN, typeof (string), "foo", "foo");
//			AssertDatatype (schema, 6, XmlTokenizedType.NMTOKEN, typeof (string []), "f o o", new string [] {"f",  "o",  "o"});
        }
コード例 #23
0
ファイル: XmlSchemas.cs プロジェクト: forki/Yaaf.Xmpp.Runtime
        object Find(XmlSchema schema, XmlQualifiedName name, Type type)
        {
            if (!schema.IsCompiled)
            {
                schema.Compile(null);
            }

            XmlSchemaObjectTable tbl = null;

            if (type == typeof(XmlSchemaSimpleType) || type == typeof(XmlSchemaComplexType))
            {
                tbl = schema.SchemaTypes;
            }
            else if (type == typeof(XmlSchemaAttribute))
            {
                tbl = schema.Attributes;
            }
            else if (type == typeof(XmlSchemaAttributeGroup))
            {
                tbl = schema.AttributeGroups;
            }
            else if (type == typeof(XmlSchemaElement))
            {
                tbl = schema.Elements;
            }
            else if (type == typeof(XmlSchemaGroup))
            {
                tbl = schema.Groups;
            }
            else if (type == typeof(XmlSchemaNotation))
            {
                tbl = schema.Notations;
            }

            object res = (tbl != null) ? tbl [name] : null;

            if (res != null && res.GetType() != type)
            {
                return(null);
            }
            else
            {
                return(res);
            }
        }
コード例 #24
0
        public void Bug81360()
        {
            string        schemaFile = "Test/XmlFiles/xsd/81360.xsd";
            XmlTextReader treader    = new XmlTextReader(schemaFile);
            XmlSchema     sc         = XmlSchema.Read(treader, null);

            sc.Compile(null);
            string              xml       = @"<body xmlns='" + sc.TargetNamespace + "'><div></div></body>";
            XmlTextReader       reader    = new XmlTextReader(new StringReader(xml));
            XmlValidatingReader validator = new XmlValidatingReader(reader);

            validator.Schemas.Add(sc);
            validator.ValidationType = ValidationType.Schema;
            while (!validator.EOF)
            {
                validator.Read();
            }
        }
コード例 #25
0
        public void v7(object param0)
        {
            Initialize();

            try
            {
                XmlSchema schema = XmlSchema.Read(CreateReader(Path.Combine(TestData._Root, param0.ToString())), ValidationCallback);
#pragma warning disable 0618
                schema.Compile(ValidationCallback);
#pragma warning restore 0618
            }
            catch (XmlException e)
            {
                CError.Compare(e.Message.Contains("DTD"), true, "Some other error thrown");
                return;
            }

            Assert.True(false);
        }
コード例 #26
0
        public void v8(object param0)
        {
            Initialize();

            try
            {
                XmlSchema schema = XmlSchema.Read(CreateReader(Path.Combine(TestData._Root, param0.ToString())), ValidationCallback);
#pragma warning disable 0618
                schema.Compile(ValidationCallback);
#pragma warning restore 0618
            }
            catch (XmlException)
            {
                Assert.True(false); //exepect a validation warning for unresolvable schema location
            }

            CError.Compare(warningCount, 0, "Warning Count mismatch");
            return;
        }
コード例 #27
0
        private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected)
        {
            passed = true;

            XmlSchema schema = new XmlSchema();

            XmlSchemaSimpleType testType = new XmlSchemaSimpleType();

            testType.Name = "TestType";

            XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();

            testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

            if (length != "-")
            {
                XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
                _length.Value = length;
                testTypeRestriction.Facets.Add(_length);
            }
            if (minLength != "-")
            {
                XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
                _minLength.Value = minLength;
                testTypeRestriction.Facets.Add(_minLength);
            }
            if (maxLength != "-")
            {
                XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
                _maxLength.Value = maxLength;
                testTypeRestriction.Facets.Add(_maxLength);
            }

            testType.Content = testTypeRestriction;
            schema.Items.Add(testType);
            schema.Compile(new ValidationEventHandler(ValidationCallbackOne));

            Assert(
                (passed ? "Test passed, should have failed" : "Test failed, should have passed") +
                ": " + length + " " + minLength + " " + maxLength,
                expected == passed);
        }
コード例 #28
0
        public void v11(object param0)
        {
            Initialize();

            try
            {
                XmlSchema schema = XmlSchema.Read(CreateReader(TestData._Root + param0.ToString(), false), ValidationCallback);
#pragma warning disable 0618
                schema.Compile(ValidationCallback);
#pragma warning restore 0618
            }
            catch (XmlException)
            {
                Assert.True(false);
            }

            CError.Compare(warningCount, 0, "Warning Count mismatch");
            CError.Compare(errorCount, 0, "Warning Count mismatch");
            return;
        }
コード例 #29
0
ファイル: XsdSchemaNormalizer.cs プロジェクト: kalyon/NBi
        private static bool NormalizeXmlSchema(String url, TextWriter writer)
        {
            try
            {
                XmlTextReader txtRead = new XmlTextReader(url);
                XmlSchema     sch     = XmlSchema.Read(txtRead, null);

                // Compiling Schema
                sch.Compile(null);

                var outSch = XmlSchemaIncludeNormalizer.BuildIncludeFreeXmlSchema(sch);

                outSch.Write(writer);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
            return(true);
        }
コード例 #30
0
        public void v6(object param0)
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += ValidationCallback;
            var reader = new XmlTextReader(Path.Combine(TestData._Root, param0.ToString()));

            reader.XmlResolver = new XmlUrlResolver();
            XmlSchema schema = XmlSchema.Read(reader, ValidationCallback);

#pragma warning disable 0618
            schema.Compile(ValidationCallback);
#pragma warning restore 0618

            xss.Add(schema);

            // expect a validation warning for unresolvable schema location
            CError.Compare(warningCount, 0, "Warning Count mismatch");
            CError.Compare(errorCount, 0, "Error Count mismatch");
        }
コード例 #31
0
 void GenerateXmlSchema(String[] formats, String fileFormatType)
   {
   StreamWriter writer = File.CreateText(xmlSchemaFile + "_" + fileFormatType + ".xml");		
   XmlSchema schema;
   XmlSchemaElement element;
   XmlSchemaComplexType complexType;
   XmlSchemaSequence sequence;
   schema = new XmlSchema();
   element = new XmlSchemaElement();
   schema.Items.Add(element);
   element.Name = "Table";
   complexType = new XmlSchemaComplexType();
   element.SchemaType = complexType;
   sequence = new XmlSchemaSequence();
   complexType.Particle = sequence;
   element = new XmlSchemaElement();
   element.Name = "Number";
   element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
   sequence.Items.Add(element);
   for(int i=0; i<formats.Length; i++){
   element = new XmlSchemaElement();
   element.Name = formats[i];
   element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
   sequence.Items.Add(element);
   }
   schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
   schema.Write(writer);
   writer.Close();
   }
コード例 #32
0
 private void WriteXMLForCultures(CultureInfo[] cultures)
 {
     StreamWriter writer = File.CreateText("CultureSchema.xml");		
     XmlSchema schema;
     XmlSchemaElement element;
     XmlSchemaComplexType complexType;
     XmlSchemaSequence sequence;
     schema = new XmlSchema();
     element = new XmlSchemaElement();
     schema.Items.Add(element);
     element.Name = "Table";
     complexType = new XmlSchemaComplexType();
     element.SchemaType = complexType;
     sequence = new XmlSchemaSequence();
     complexType.Particle = sequence;
     element = new XmlSchemaElement();
     element.Name = "CultureName";
     element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
     sequence.Items.Add(element);
     schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
     schema.Write(writer);
     writer.Close();     
     writer = File.CreateText("CultureData.xml");
     XmlTextWriter myXmlTextWriter = new XmlTextWriter(writer);
     myXmlTextWriter.Formatting = Formatting.Indented;
     myXmlTextWriter.WriteStartElement("NewDataSet");
     for(int j=0; j<cultures.Length; j++)
     {
         myXmlTextWriter.WriteStartElement("Table");
         myXmlTextWriter.WriteElementString("CultureName", cultures[j].LCID.ToString());
         myXmlTextWriter.WriteEndElement();
     }
     myXmlTextWriter.WriteEndElement();
     myXmlTextWriter.Flush();
     myXmlTextWriter.Close();
 }