//[Variation(Desc = "v3 - Contains with existing schema, Remove it, Contains again")]
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema = sc.Add("xsdauthor", TestData._XsdAuthor);
            Assert.Equal(sc.Contains("xsdauthor"), true);

            sc.Remove(Schema);

            Assert.Equal(sc.Contains("xsdauthor"), false);

            return;
        }
Esempio n. 2
0
        public static void LoadCompositionSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            if (!xs.Contains(OpenEhrNamespace))
            {
                System.Xml.Schema.XmlSchema compositionSchema = GetOpenEhrSchema("Composition");

                System.Xml.Schema.XmlSchema contentSchema = GetOpenEhrSchema("Content");
                compositionSchema.Includes.RemoveAt(0);

                foreach (System.Xml.Schema.XmlSchemaObject item in contentSchema.Items)
                {
                    compositionSchema.Items.Add(item);
                }

                System.Xml.Schema.XmlSchema structureSchema = GetOpenEhrSchema("Structure");

                foreach (System.Xml.Schema.XmlSchemaObject item in structureSchema.Items)
                {
                    compositionSchema.Items.Add(item);
                }

                System.Xml.Schema.XmlSchema baseTypesSchema = GetOpenEhrSchema("BaseTypes");

                foreach (System.Xml.Schema.XmlSchemaObject item in baseTypesSchema.Items)
                {
                    compositionSchema.Items.Add(item);
                }

                xs.Add(compositionSchema);

                xs.Compile();
            }
        }
Esempio n. 3
0
        public static void LoadEhrStatusSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            if (!xs.Contains(OpenEhrNamespace))
            {
                System.Xml.Schema.XmlSchema ehrStatusSchema = GetOpenEhrSchema("EhrStatus");
                ehrStatusSchema.Includes.RemoveAt(0);

                System.Xml.Schema.XmlSchema structureSchema = GetOpenEhrSchema("Structure");

                foreach (System.Xml.Schema.XmlSchemaObject item in structureSchema.Items)
                {
                    ehrStatusSchema.Items.Add(item);
                }

                System.Xml.Schema.XmlSchema baseTypesSchema = GetOpenEhrSchema("BaseTypes");

                foreach (System.Xml.Schema.XmlSchemaObject item in baseTypesSchema.Items)
                {
                    ehrStatusSchema.Items.Add(item);
                }

                xs.Add(ehrStatusSchema);

                xs.Compile();
            }
        }
Esempio n. 4
0
        public static void LoadStructureSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            if (!xs.Contains(OpenEhrNamespace))
            {
                if (structureSchema == null)
                {
                    lock (structureSchemaLock)
                    {
                        if (structureSchema == null)
                        {
                            System.Xml.Schema.XmlSchema tempSchema = GetOpenEhrSchema("Structure");
                            tempSchema.Includes.RemoveAt(0);

                            System.Xml.Schema.XmlSchema includeSchema = GetOpenEhrSchema("BaseTypes");

                            foreach (System.Xml.Schema.XmlSchemaObject item in includeSchema.Items)
                            {
                                tempSchema.Items.Add(item);
                            }

                            structureSchema = tempSchema;
                        }
                    }
                }
                xs.Add(structureSchema);
            }
        }
        //[Variation(Desc = "v1 - Contains with null")]
        public void v1()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            Assert.Equal(sc.Contains((String)null), false);

            return;
        }
 //[Variation(Desc = "v2 - Contains with non existing ns", Priority = 0)]
 public void v2()
 {
     XmlSchemaSet sc = new XmlSchemaSet();
     sc.Add("xsdauthor", TestData._XsdAuthor);
     Assert.Equal(sc.Contains("test"), false);
     return;
 }
Esempio n. 7
0
        public void v2()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            try
            {
                XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
                CError.Compare(sc.Count, 1, "AddCount");
                CError.Compare(sc.Contains(Schema1), true, "AddContains");
                CError.Compare(sc.IsCompiled, false, "AddIsCompiled");

                XmlSchema Schema2 = XmlSchema.Read(new StreamReader(new FileStream(TestData._XsdNoNs, FileMode.Open, FileAccess.Read)), null);

                sc.Compile();
                CError.Compare(sc.Count, 1, "Compile");
                CError.Compare(sc.Contains(Schema1), true, "Contains");

                sc.Reprocess(Schema2);
                CError.Compare(sc.Count, 1, "Reprocess");
                CError.Compare(sc.Contains(Schema2), true, "Contains");
            }
            catch (ArgumentException e)
            {
                _output.WriteLine(e.ToString());
                CError.Compare(sc.Count, 1, "AE");
                return;
            }
            Assert.True(false);
        }
        //[Variation(Desc = "v3 - Contains with existing schema, Remove it, Contains again", Priority = 0)]
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
#pragma warning disable 0618
            XmlSchemaCollection scl = new XmlSchemaCollection();
#pragma warning restore 0618

            XmlSchema Schema = scl.Add(null, TestData._XsdAuthor);
            sc.Add(Schema);

            Assert.Equal(sc.Contains(Schema), true);

            sc.Remove(Schema);

            Assert.Equal(sc.Contains(Schema), false);

            return;
        }
Esempio n. 9
0
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema = XmlSchema.Read(new StreamReader(new FileStream(TestData._FileXSD1, FileMode.Open, FileAccess.Read)), null);
            XmlSchema SchemaNew1 = sc.Add(Schema);
            XmlSchema SchemaNew2 = sc.Add(Schema);

            Assert.Equal(sc.Count, 1);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, false);
            Assert.Equal(Schema == SchemaNew1, true);
            Assert.Equal(Schema == SchemaNew2, true);

            sc.Compile();
            Assert.Equal(sc.Count, 1);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, true);
        }
Esempio n. 10
0
 public void v1()
 {
     XmlSchemaSet sc = new XmlSchemaSet();
     try
     {
         sc.Add((XmlSchema)null);
     }
     catch (ArgumentNullException)
     {
         try
         {
             Assert.Equal(sc.Count, 0);
             Assert.Equal(sc.Contains((XmlSchema)null), false);
         }
         catch (ArgumentNullException)
         {
             Assert.Equal(sc.Contains((string)null), false);
             Assert.Equal(sc.IsCompiled, false);
             return;
         }
     }
     Assert.True(false);
 }
 //[Variation(Desc = "v1 - Contains with null")]
 public void v1()
 {
     try
     {
         XmlSchemaSet sc = new XmlSchemaSet();
         sc.Contains((XmlSchema)null);
     }
     catch (ArgumentNullException)
     {
         // GLOBALIZATION
         return;
     }
     Assert.True(false);
 }
Esempio n. 12
0
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();
            XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
            XmlSchema Schema2 = sc.Add("test", TestData._XsdNoNs);
            sc.Compile();
            sc.Remove(Schema1);

            CError.Compare(sc.Count, 1, "Count");
            ICollection Col = sc.Schemas();
            CError.Compare(Col.Count, 1, "ICollection.Count");
            CError.Compare(sc.Contains("test"), true, "Contains");

            return;
        }
Esempio n. 13
0
 public static void LoadBaseTypesSchema(System.Xml.Schema.XmlSchemaSet xs)
 {
     if (!xs.Contains(OpenEhrNamespace))
     {
         if (baseTypesSchema == null)
         {
             lock (baseTypesSchemaLock)
             {
                 if (baseTypesSchema == null)
                 {
                     baseTypesSchema = GetOpenEhrSchema("BaseTypes");
                 }
             }
         }
         xs.Add(baseTypesSchema);
     }
 }
Esempio n. 14
0
        void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            compilationItems = new XmlSchemaObjectCollection();
            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                if (ext == null)
                {
                    error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
                    continue;
                }

                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                Stream stream = null;
                string url    = null;
                if (resolver != null)
                {
                    url = GetResolvedUri(resolver, ext.SchemaLocation);
                    if (handledUris.Contains(url))
                    {
                        // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
                        continue;
                    }
                    handledUris.Add(url, url);
                    try {
                        stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream;
                    } catch (Exception) {
                        // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
                        warn(handler, "Could not resolve schema location URI: " + url);
                        stream = null;
                    }
                }

                // Process redefinition children in advance.
                XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
                if (redefine != null)
                {
                    for (int j = 0; j < redefine.Items.Count; j++)
                    {
                        XmlSchemaObject redefinedObj = redefine.Items [j];
                        redefinedObj.isRedefinedComponent = true;
                        redefinedObj.isRedefineChild      = true;
                        if (redefinedObj is XmlSchemaType ||
                            redefinedObj is XmlSchemaGroup ||
                            redefinedObj is XmlSchemaAttributeGroup)
                        {
                            compilationItems.Add(redefinedObj);
                        }
                        else
                        {
                            error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
                        }
                    }
                }

                XmlSchema includedSchema = null;
                if (stream == null)
                {
                    // It is missing schema components.
                    missedSubComponents = true;
                    continue;
                }
                else
                {
                    XmlTextReader xtr = null;
                    try {
                        xtr            = new XmlTextReader(url, stream, nameTable);
                        includedSchema = XmlSchema.Read(xtr, handler);
                    } finally {
                        if (xtr != null)
                        {
                            xtr.Close();
                        }
                    }
                    includedSchema.schemas = schemas;
                }
                includedSchema.SetParent();
                ext.Schema = includedSchema;

                // Set - actual - target namespace for the included schema * before compilation*.
                XmlSchemaImport import = ext as XmlSchemaImport;
                if (import != null)
                {
                    if (TargetNamespace == includedSchema.TargetNamespace)
                    {
                        error(handler, "Target namespace must be different from that of included schema.");
                        continue;
                    }
                    else if (includedSchema.TargetNamespace != import.Namespace)
                    {
                        error(handler, "Attribute namespace and its importing schema's target namespace must be the same.");
                        continue;
                    }
                }
                else
                {
                    if (TargetNamespace == null &&
                        includedSchema.TargetNamespace != null)
                    {
                        error(handler, "Target namespace is required to include a schema which has its own target namespace");
                        continue;
                    }
                    else if (TargetNamespace != null &&
                             includedSchema.TargetNamespace == null)
                    {
                        includedSchema.TargetNamespace = TargetNamespace;
                    }
                }

                // Do not compile included schema here.

                AddExternalComponentsTo(includedSchema, compilationItems);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
        // Segregate the schemas containing abstract types from those 
        // containing regular XML definitions.  This is important because
        // when you import something returning the ur-type (object), then
        // you need to import ALL types/elements within ALL schemas.  We
        // don't want the RPC-based types leaking over into the XML-based
        // element definitions or literal types in the encoded schemas,
        // beacase it can cause schema coimpilation falure. 
        static void CollectEncodedAndLiteralSchemas(WsdlNS.ServiceDescriptionCollection serviceDescriptions, XmlSchemas encodedSchemas, XmlSchemas literalSchemas, XmlSchemaSet allSchemas)
        {
            XmlSchema wsdl = StockSchemas.CreateWsdl();
            XmlSchema soap = StockSchemas.CreateSoap();
            XmlSchema soapEncoding = StockSchemas.CreateSoapEncoding();

            Hashtable references = new Hashtable();
            if (!allSchemas.Contains(wsdl.TargetNamespace))
            {
                references[soap] = wsdl;
            }

            if (!allSchemas.Contains(soap.TargetNamespace))
            {
                references[soap] = soap;
            }
            if (!allSchemas.Contains(soapEncoding.TargetNamespace))
            {
                references[soapEncoding] = soapEncoding;
            }
            foreach (WsdlNS.ServiceDescription description in serviceDescriptions)
            {
                foreach (WsdlNS.Message message in description.Messages)
                {
                    foreach (WsdlNS.MessagePart part in message.Parts)
                    {
                        bool isEncoded;
                        bool isLiteral;
                        FindUse(part, out isEncoded, out isLiteral);
                        if (part.Element != null && !part.Element.IsEmpty)
                        {
                            XmlSchemaElement element = FindSchemaElement(allSchemas, part.Element);
                            if (element != null)
                            {
                                AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references);
                                if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty)
                                {
                                    XmlSchemaType type = FindSchemaType(allSchemas, element.SchemaTypeName);
                                    if (type != null)
                                    {
                                        AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references);
                                    }
                                }
                            }
                        }
                        if (part.Type != null && !part.Type.IsEmpty)
                        {
                            XmlSchemaType type = FindSchemaType(allSchemas, part.Type);
                            if (type != null)
                            {
                                AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, encodedSchemas, literalSchemas, references);
                            }
                        }
                    }
                }
            }

            Hashtable imports;
            foreach (XmlSchemas schemas in new XmlSchemas[] { encodedSchemas, literalSchemas })
            {
                // collect all imports
                imports = new Hashtable();
                foreach (XmlSchema schema in schemas)
                {
                    AddImport(schema, imports, allSchemas);
                }
                // make sure we add them to the corresponding schema collections
                foreach (XmlSchema schema in imports.Keys)
                {
                    if (references[schema] == null && !schemas.Contains(schema))
                    {
                        schemas.Add(schema);
                    }
                }
            }

            // If a schema was not referenced by either a literal or an encoded message part,
            // add it to both collections. There's no way to tell which it should be.
            imports = new Hashtable();
            foreach (XmlSchema schema in allSchemas.Schemas())
            {
                if (!encodedSchemas.Contains(schema) && !literalSchemas.Contains(schema))
                {
                    AddImport(schema, imports, allSchemas);
                }
            }

            // make sure we add them to the corresponding schema collections
            foreach (XmlSchema schema in imports.Keys)
            {
                if (references[schema] != null)
                    continue;
                if (!encodedSchemas.Contains(schema))
                {
                    encodedSchemas.Add(schema);
                }
                if (!literalSchemas.Contains(schema))
                {
                    literalSchemas.Add(schema);
                }
            }
            if (encodedSchemas.Count > 0)
            {
                foreach (XmlSchema schema in references.Values)
                {
                    encodedSchemas.AddReference(schema);
                }
            }
            if (literalSchemas.Count > 0)
            {
                foreach (XmlSchema schema in references.Values)
                {
                    literalSchemas.AddReference(schema);
                }
            }
            AddSoapEncodingSchemaIfNeeded(literalSchemas);
        }
Esempio n. 16
0
		// Import

		void PrepareSchemas (XmlSchemaSet schemas)
		{
			if (!schemas.Contains (KnownTypeCollection.MSSimpleNamespace))
				schemas.Add (XmlSchema.Read (GetType ().Assembly.GetManifestResourceStream ("mstypes.schema"), null));

			if (!schemas.IsCompiled)
				schemas.Compile ();
		}
Esempio n. 17
0
        public void v12()
        {
            bWarningCallback = false;
            bErrorCallback = false;

            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();

            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            XmlSchema Schema1 = sc.Add(null, TestData._Root + "include_v1_a.xsd");
            CError.Compare(sc.Count, 1, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Count after add/comp");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add/comp");
            ///edit
            XmlSchemaInclude inc = new XmlSchemaInclude();
            inc.SchemaLocation = "include_v2.xsd";
            Schema1.Includes.Add(inc);

            sc.Reprocess(Schema1);
            ValidateSchemaSet(sc, 1, false, 1, 0, 0, "Validation after edit/reprocess");
            CError.Compare(bWarningCallback, false, "Warning repr");
            CError.Compare(bErrorCallback, true, "Error repr");

            sc.Compile();
            ValidateSchemaSet(sc, 1, false, 1, 0, 0, "Validation after comp/reprocess");
            CError.Compare(bWarningCallback, false, "Warning comp");
            CError.Compare(bErrorCallback, true, "Error comp");
            CError.Compare(Schema1.IsCompiled, false, "IsCompiled on SOM");
            return;
        }
Esempio n. 18
0
        public void v8()
        {
            bWarningCallback = false;
            bErrorCallback = false;

            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();
            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

            XmlSchema Schema1 = sc.Add(null, TestData._Root + "import_v1_a.xsd");
            CError.Compare(sc.Count, 2, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 2, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");

            //edit
            foreach (XmlSchemaImport imp in Schema1.Includes)
            {
                imp.SchemaLocation = "bogus";
                imp.Schema = null;
            }

            sc.Reprocess(Schema1);

            CError.Compare(bWarningCallback, true, "Warning");
            CError.Compare(bErrorCallback, false, "Error");

            CError.Compare(sc.Count, 2, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");
            CError.Compare(sc.IsCompiled, false, "IsCompiled");

            sc.Compile();

            CError.Compare(sc.IsCompiled, true, "IsCompiled");
            CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM");

            return;
        }
Esempio n. 19
0
        public void v5()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
            CError.Compare(sc.Count, 1, "AddCount");
            CError.Compare(sc.Contains(Schema1), true, "AddContains");
            CError.Compare(sc.IsCompiled, false, "AddIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "CompileCount");
            CError.Compare(sc.Contains(Schema1), true, "CompileContains");
            //edit
            XmlSchemaAttribute attributeDog = new XmlSchemaAttribute();

            Schema1.Items.Add(attributeDog);
            attributeDog.Name = "dog";
            attributeDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

            sc.Reprocess(Schema1);
            CError.Compare(sc.Count, 1, "ReprocessCount");
            CError.Compare(sc.Contains(Schema1), true, "ReprocessContains");
            CError.Compare(sc.IsCompiled, false, "ReprocessIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Count Compile");
            CError.Compare(sc.IsCompiled, true, "IsCompiled Compile");
            CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM Compile");
            return;
        }
Esempio n. 20
0
 bool LoadSchema(XmlSchemaSet set, SchemaResolver resolver, XmlNode ctx, string nsuri, string filename)
 {
     try {
         Uri baseUri = this.baseUri;
         if (!string.IsNullOrEmpty(ctx.BaseURI)) {
             baseUri = new Uri(ctx.BaseURI);
         }
         Uri resolved;
         if (baseUri != null) {
             resolved = new Uri(baseUri, filename);
         } else {
             resolved = new Uri(filename, UriKind.RelativeOrAbsolute);
         }
         XmlSchema s = resolver.GetEntity(resolved, "", typeof(XmlSchema)) as XmlSchema;
         if ((s.TargetNamespace+"") != (nsuri+"")) {
             ReportError(Severity.Warning, SR.TNSMismatch, ctx);
         } else if (!set.Contains(s)) {
             set.Add(s);
             return true;
         }
     } catch (Exception e) {
         ReportError(Severity.Warning, string.Format(SR.SchemaLoadError, filename, e.Message), ctx);
     }
     return false;
 }
 public static XmlSchemaComplexType GetTypedTableSchema(XmlSchemaSet xs)
 {
     XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType();
     XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
     UserWorkingProfileDS userWorkingProfileDS = new UserWorkingProfileDS();
     XmlSchemaAny xmlSchemaAny = new XmlSchemaAny();
     xmlSchemaAny.Namespace = "http://www.w3.org/2001/XMLSchema";
     xmlSchemaAny.MinOccurs = 0m;
     xmlSchemaAny.MaxOccurs = 79228162514264337593543950335m;
     xmlSchemaAny.ProcessContents = XmlSchemaContentProcessing.Lax;
     xmlSchemaSequence.Items.Add(xmlSchemaAny);
     XmlSchemaAny xmlSchemaAny2 = new XmlSchemaAny();
     xmlSchemaAny2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     xmlSchemaAny2.MinOccurs = 1m;
     xmlSchemaAny2.ProcessContents = XmlSchemaContentProcessing.Lax;
     xmlSchemaSequence.Items.Add(xmlSchemaAny2);
     XmlSchemaAttribute xmlSchemaAttribute = new XmlSchemaAttribute();
     xmlSchemaAttribute.Name = "namespace";
     xmlSchemaAttribute.FixedValue = userWorkingProfileDS.Namespace;
     xmlSchemaComplexType.Attributes.Add(xmlSchemaAttribute);
     XmlSchemaAttribute xmlSchemaAttribute2 = new XmlSchemaAttribute();
     xmlSchemaAttribute2.Name = "tableTypeName";
     xmlSchemaAttribute2.FixedValue = "TemplateItemDataTable";
     xmlSchemaComplexType.Attributes.Add(xmlSchemaAttribute2);
     xmlSchemaComplexType.Particle = xmlSchemaSequence;
     XmlSchema schemaSerializable = userWorkingProfileDS.GetSchemaSerializable();
     XmlSchemaComplexType result;
     if (xs.Contains(schemaSerializable.TargetNamespace))
     {
         MemoryStream memoryStream = new MemoryStream();
         MemoryStream memoryStream2 = new MemoryStream();
         try
         {
             schemaSerializable.Write(memoryStream);
             IEnumerator enumerator = xs.Schemas(schemaSerializable.TargetNamespace).GetEnumerator();
             while (enumerator.MoveNext())
             {
                 XmlSchema xmlSchema = (XmlSchema)enumerator.Current;
                 memoryStream2.SetLength(0L);
                 xmlSchema.Write(memoryStream2);
                 if (memoryStream.Length == memoryStream2.Length)
                 {
                     memoryStream.Position = 0L;
                     memoryStream2.Position = 0L;
                     while (memoryStream.Position != memoryStream.Length && memoryStream.ReadByte() == memoryStream2.ReadByte())
                     {
                     }
                     if (memoryStream.Position == memoryStream.Length)
                     {
                         result = xmlSchemaComplexType;
                         return result;
                     }
                 }
             }
         }
         finally
         {
             if (memoryStream != null)
             {
                 memoryStream.Close();
             }
             if (memoryStream2 != null)
             {
                 memoryStream2.Close();
             }
         }
     }
     xs.Add(schemaSerializable);
     result = xmlSchemaComplexType;
     return result;
 }
Esempio n. 22
0
        public void v5()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema = XmlSchema.Read(new StreamReader(new FileStream(TestData._XsdAuthor, FileMode.Open, FileAccess.Read)), null);
            XmlSchema SchemaNew1 = sc.Add(Schema);
            XmlSchema SchemaNew2 = sc.Add(null, TestData._XsdAuthorNoNs);

            // both schemas are added but they are dup
            Assert.Equal(sc.Count, 2);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, false);

            // check its not the same schema as first
            Assert.Equal(Schema == SchemaNew1, true);
            Assert.Equal(Schema == SchemaNew2, false);

            sc.Compile();
            Assert.Equal(sc.Count, 2);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, true);
        }
Esempio n. 23
0
        private int AddSchema(string path1, string path2, int expCount)
        {
            XmlSchemaSet s = new XmlSchemaSet();
            s.XmlResolver = new XmlUrlResolver();

            XmlSchema aSchema = XmlSchema.Read(new XmlTextReader(path1), null);
            XmlSchema bSchema = XmlSchema.Read(new XmlTextReader(path2), null);
            Assert.Equal(s.Count, 0);
            Assert.Equal(s.Contains(aSchema), false);
            Assert.Equal(s.Contains(bSchema), false);
            Assert.Equal(s.IsCompiled, false);

            s.Add(aSchema);
            Assert.Equal(s.Count, expCount);
            Assert.Equal(s.Contains(aSchema), true);
            Assert.Equal(s.Contains(bSchema), false);
            Assert.Equal(s.IsCompiled, false);

            s.Add(bSchema);
            Assert.Equal(s.Count, expCount + 1);
            Assert.Equal(s.Contains(aSchema), true);
            Assert.Equal(s.Contains(bSchema), true);
            Assert.Equal(s.IsCompiled, false);
            try
            {
                s.Compile();
                _output.WriteLine("No exception thrown");
                Assert.True(false);
            }
            catch (XmlSchemaException e)
            {
                _output.WriteLine(e.ToString());
                Assert.Equal(s.Count, expCount + 1);
                Assert.Equal(s.Contains(aSchema), true);
                Assert.Equal(s.Contains(bSchema), true);
                Assert.Equal(s.IsCompiled, false);
            }

            return 0;
        }
Esempio n. 24
0
        public void v10()
        {
            XmlCachedSchemaSetResolver resolver = new XmlCachedSchemaSetResolver();
            XmlTextReader r = new XmlTextReader(Path.Combine(TestData._Root, @"RedefineEmployee.xsd"));
            XmlSchema s = XmlSchema.Read(r, null);
            resolver.Add(new Uri(s.SourceUri), s);

            XmlTextReader r2 = new XmlTextReader(Path.Combine(TestData._Root, @"BaseEmployee2.xsd"));
            XmlSchema s2 = XmlSchema.Read(r2, null);
            resolver.Add(new Uri(s2.SourceUri), s2);

            XmlSchemaSet set = new XmlSchemaSet();
            set.ValidationEventHandler += new ValidationEventHandler(callback);
            set.XmlResolver = resolver;

            set.Add(s2);
            Assert.Equal(set.Count, 1);
            Assert.Equal(set.Contains(s2), true);
            Assert.Equal(set.IsCompiled, false);

            set.Add(s);
            Assert.Equal(set.Count, 2);
            Assert.Equal(set.Contains(s), true);
            Assert.Equal(set.IsCompiled, false);

            set.Compile();
            Assert.Equal(set.Count, 2);
            Assert.Equal(set.Contains(s2), true);
            Assert.Equal(set.Contains(s), true);
            Assert.Equal(set.IsCompiled, true);

            XmlTextReader r3 = new XmlTextReader(Path.Combine(TestData._Root, @"BaseEmployee2.xsd"));
            XmlSchema s3 = XmlSchema.Read(r3, null);
            resolver.Add(new Uri(s3.SourceUri), s3);

            //Clear includes in S
            foreach (XmlSchemaExternal ext in s.Includes)
            {
                ext.Schema = null;
            }
            XmlSchemaSet set2 = new XmlSchemaSet();
            set2.ValidationEventHandler += new ValidationEventHandler(callback);
            set2.XmlResolver = resolver;
            set2.Add(s3);
            Assert.Equal(set2.Count, 1);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), false);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, false);

            set2.Add(s);
            Assert.Equal(set2.Count, 2);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), true);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, false);

            set2.Compile();
            Assert.Equal(set2.Count, 2);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), true);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, true);

            Assert.Equal(errorCount, 0);
        }
Esempio n. 25
0
        public void v11()
        {
            XmlCachedSchemaSetResolver resolver = new XmlCachedSchemaSetResolver();

            XmlTextReader r = new XmlTextReader(Path.Combine(TestData._Root, @"RedefineEmployee.xsd"));
            XmlSchema s = XmlSchema.Read(r, null);
            resolver.Add(new Uri(s.SourceUri), s);

            XmlTextReader r2 = new XmlTextReader(Path.Combine(TestData._Root, @"BaseEmployee2.xsd"));
            XmlSchema s2 = XmlSchema.Read(r2, null);
            resolver.Add(new Uri(s2.SourceUri), s2);

            XmlSchemaSet set = new XmlSchemaSet();
            set.XmlResolver = resolver;
            set.Add(s2);
            Assert.Equal(set.Count, 1);
            Assert.Equal(set.Contains(s2), true);
            Assert.Equal(set.IsCompiled, false);

            set.Add(s);
            Assert.Equal(set.Count, 2);
            Assert.Equal(set.Contains(s), true);
            Assert.Equal(set.IsCompiled, false);

            set.Compile();
            Assert.Equal(set.Count, 2);
            Assert.Equal(set.Contains(s2), true);
            Assert.Equal(set.Contains(s), true);
            Assert.Equal(set.IsCompiled, true);

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas = set;

            using (XmlReader reader = XmlReader.Create(Path.Combine(TestData._Root, "EmployeesDefaultPrefix.xml"), settings))
            {
                while (reader.Read()) ;
            }
            XmlTextReader r3 = new XmlTextReader(Path.Combine(TestData._Root, @"BaseEmployee2.xsd"));
            XmlSchema s3 = XmlSchema.Read(r3, null);
            resolver.Add(new Uri(s3.SourceUri), s3);

            XmlSchemaSet set2 = new XmlSchemaSet();
            set2.XmlResolver = resolver;
            set2.Add(s3);
            Assert.Equal(set2.Count, 1);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), false);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, false);

            foreach (XmlSchemaRedefine redefine in s.Includes)
            {
                redefine.Schema = null;
            }

            set2.Add(s);
            Assert.Equal(set2.Count, 2);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), true);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, false);

            set2.Compile();
            Assert.Equal(set2.Count, 2);
            Assert.Equal(set2.Contains(s2), false);
            Assert.Equal(set2.Contains(s), true);
            Assert.Equal(set2.Contains(s3), true);
            Assert.Equal(set2.IsCompiled, true);

            settings.Schemas = set2;

            using (XmlReader reader = XmlReader.Create(Path.Combine(TestData._Root, "EmployeesDefaultPrefix.xml"), settings))
            {
                while (reader.Read()) ;
            }
            Assert.Equal(errorCount, 0);
        }
Esempio n. 26
0
 public bool Contains(string ns)
 {
     lock (schemaSet) {
         return(schemaSet.Contains(ns));
     }
 }
        internal ConfigurationElement Read()
        {
            XmlSchemaSet schemas = new XmlSchemaSet();

            // load buit-in schema from resource
            schemas.Add(GetSchemaFromResource());

            if (this.loader.SchemaFileNames.Any())
            {
                AddExtensionSchemas(schemas, this.loader);
            }

            var readerSettings = new XmlReaderSettings()
            {
                Schemas = schemas,
                CloseInput = true,
                XmlResolver = new SchemaConfigurationXmlResolver(),
                ValidationType = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                  XmlSchemaValidationFlags.ReportValidationWarnings |
                                  XmlSchemaValidationFlags.ProcessSchemaLocation |
                                  XmlSchemaValidationFlags.ProcessInlineSchema
            };

            var validationExceptions = new List<Exception>();
            readerSettings.ValidationEventHandler += (s, a) =>
                {
                    //// Filter out any missing schema warnings for custom elements and its child sub elements
                    if (a.Severity == XmlSeverityType.Warning)
                    {
                        var reader = (XmlReader)s;
                        if (!schemas.Contains(reader.NamespaceURI) || reader.NamespaceURI == Constants.Namespace)
                        {
                            return;
                        }
                    }

                    //// Collect all schema validation errors
                    validationExceptions.Add(a.Exception);
                };

            XDocument doc = null;
            using (var reader = XmlReader.Create(this.File, readerSettings))
            {
                try
                {
                    doc = XDocument.Load(reader, LoadOptions.SetLineInfo);
                }
                catch (Exception e)
                {
                    validationExceptions.Add(e);
                }
            }

            if (validationExceptions.Count > 0)
            {
                throw new ConfigurationException(validationExceptions) { ConfigurationFile = this.File };
            }

            var configuration = new ConfigurationElement();

            var tes = doc.Root.Element(this.traceEventServiceName);
            configuration.TraceEventService = (tes == null) ? new TraceEventServiceElement() : TraceEventServiceElement.Read(tes);

            var sinks = doc.Root.Elements(this.sinksName).Elements();
            if (sinks != null)
            {
                configuration.SinkConfigurationElements = this.LoadSinkConfigurationElements(sinks);
            }

            return configuration;
        }
Esempio n. 28
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
Esempio n. 29
0
		void DoCompile (ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
		{
			SetParent ();
			CompilationId = col.CompilationId;
			schemas = col;
			if (!schemas.Contains (this)) // e.g. xs:import
				schemas.Add (this);

			attributeGroups.Clear ();
			attributes.Clear ();
			elements.Clear ();
			groups.Clear ();
			notations.Clear ();
			schemaTypes.Clear ();

			//1. Union and List are not allowed in block default
			if (BlockDefault != XmlSchemaDerivationMethod.All) {
				if((BlockDefault & XmlSchemaDerivationMethod.List)!=0 )
					error(handler, "list is not allowed in blockDefault attribute");
				if((BlockDefault & XmlSchemaDerivationMethod.Union)!=0 )
					error(handler, "union is not allowed in blockDefault attribute");
			}

			//2. Substitution is not allowed in finaldefault.
			if (FinalDefault != XmlSchemaDerivationMethod.All) {
				if((FinalDefault & XmlSchemaDerivationMethod.Substitution)!=0 )
					error(handler, "substitution is not allowed in finalDefault attribute");
			}

			//3. id must be of type ID
			XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

			//4. targetNamespace should be of type anyURI or absent
			if (TargetNamespace != null) {
				if (TargetNamespace.Length == 0)
					error (handler, "The targetNamespace attribute cannot have have empty string as its value.");

				if(!XmlSchemaUtil.CheckAnyUri (TargetNamespace))
					error(handler, TargetNamespace+" is not a valid value for targetNamespace attribute of schema");
			}

			//5. version should be of type normalizedString
			if (!XmlSchemaUtil.CheckNormalizedString(Version))
				error(handler, Version + "is not a valid value for version attribute of schema");

			// Compile the content of this schema

			compilationItems = new XmlSchemaObjectCollection ();
			for (int i = 0; i < Items.Count; i++) {
				compilationItems.Add (Items [i]);
			}

			// First, we run into inclusion schemas to collect 
			// compilation target items into compiledItems.
			for (int i = 0; i < Includes.Count; i++)
				ProcessExternal (handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);

			// Compilation phase.
			// At least each Compile() must give unique (qualified) name for each component.
			// It also checks self-resolvable properties correctness.
			// Post compilation schema information contribution is not done here.
			// It should be done by Validate().
			for (int i = 0; i < compilationItems.Count; i++) {
				XmlSchemaObject obj = compilationItems [i];
				if(obj is XmlSchemaAnnotation) {
					int numerr = ((XmlSchemaAnnotation)obj).Compile (handler, this);
					errorCount += numerr;
				} else if (obj is XmlSchemaAttribute) {
					XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
					int numerr = attr.Compile (handler, this);
					errorCount += numerr;
					if(numerr == 0)
					{
						XmlSchemaUtil.AddToTable (Attributes, attr, attr.QualifiedName, handler);
					}
				} else if (obj is XmlSchemaAttributeGroup) {
					XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup) obj;
					int numerr = attrgrp.Compile(handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							AttributeGroups,
							attrgrp,
							attrgrp.QualifiedName,
							handler);
				} else if (obj is XmlSchemaComplexType) {
					XmlSchemaComplexType ctype = (XmlSchemaComplexType) obj;
					int numerr = ctype.Compile (handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							schemaTypes,
							ctype,
							ctype.QualifiedName,
							handler);
				} else if (obj is XmlSchemaSimpleType) {
					XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj;
					stype.islocal = false; //This simple type is toplevel
					int numerr = stype.Compile (handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							SchemaTypes,
							stype,
							stype.QualifiedName,
							handler);
				} else if (obj is XmlSchemaElement) {
					XmlSchemaElement elem = (XmlSchemaElement) obj;
					elem.parentIsSchema = true;
					int numerr = elem.Compile (handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							Elements,
							elem,
							elem.QualifiedName,
							handler);
				} else if (obj is XmlSchemaGroup) {
					XmlSchemaGroup grp = (XmlSchemaGroup) obj;
					int numerr = grp.Compile (handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							Groups,
							grp,
							grp.QualifiedName,
							handler);
				} else if (obj is XmlSchemaNotation) {
					XmlSchemaNotation ntn = (XmlSchemaNotation) obj;
					int numerr = ntn.Compile (handler, this);
					errorCount += numerr;
					if (numerr == 0)
						XmlSchemaUtil.AddToTable (
							Notations,
							ntn,
							ntn.QualifiedName,
							handler);
				} else {
					ValidationHandler.RaiseValidationEvent (
						handler,
						null,
						String.Format ("Object of Type {0} is not valid in Item Property of Schema", obj.GetType ().Name),
						null,
						this,
						null,
						XmlSeverityType.Error);
				}
			}
		}
Esempio n. 30
0
 internal bool IsNamespaceAbsent(string ns)
 {
     return(!schemas.Contains(ns));
 }
Esempio n. 31
0
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
            CError.Compare(sc.Count, 1, "AddCount");
            CError.Compare(sc.Contains(Schema1), true, "AddContains");
            CError.Compare(sc.IsCompiled, false, "AddIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Compile");
            CError.Compare(sc.Contains(Schema1), true, "Compile Contains");

            CError.Compare(sc.IsCompiled, true, "Compile IsCompiled");
            sc.Reprocess(Schema1);
            CError.Compare(sc.Count, 1, "IsCompiled on set");
            CError.Compare(sc.IsCompiled, false, "Reprocess IsCompiled");
            CError.Compare(sc.Contains(Schema1), true, "Reprocess Contains");

            return;
        }
        public void v6()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                //after compile
                XmlSchema Schema1 = sc.Add("ns-b", Path.Combine(TestData._Root, "import_v4_b.xsd"));
                XmlSchema Schema2 = sc.Add(null, Path.Combine(TestData._Root, "import_v5_a.xsd")); // param as filename
                sc.Compile();
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 2, "Count");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains(String.Empty), true, "Contains");
                CError.Compare(sc.Contains("ns-a"), true, "Contains");

                sc.RemoveRecursive(Schema2);
                ICollection Col = sc.Schemas();
                CError.Compare(Col.Count, 0, "ICollection.Count");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains(String.Empty), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");

                //before compile
                Schema1 = sc.Add("ns-b", Path.Combine(TestData._Root, "import_v4_b.xsd"));
                Schema2 = sc.Add(null, Path.Combine(TestData._Root, "import_v5_a.xsd")); // param as filename
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 2, "Count");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains(String.Empty), true, "Contains");
                CError.Compare(sc.Contains("ns-a"), true, "Contains");
                sc.RemoveRecursive(Schema2);
                Col = sc.Schemas();
                CError.Compare(Col.Count, 0, "ICollection.Count");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains(String.Empty), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Esempio n. 33
0
        public void v7()
        {
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
                CError.Compare(sc.Count, 1, "Count after add");
                CError.Compare(sc.Contains(Schema1), true, "Contains after add");

                sc.Compile();
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains(Schema1), true, "Contains");

                //edit
                XmlSchemaAttribute attributeDog = new XmlSchemaAttribute();
                Schema1.Items.Add(attributeDog);
                attributeDog.Name = "dog";
                attributeDog.SchemaTypeName = new XmlQualifiedName("blah", "http://www.w3.org/2001/XMLSchema");
                sc.Reprocess(Schema1);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains(Schema1), true, "Contains");
                CError.Compare(sc.IsCompiled, false, "IsCompiled");
                sc.Compile();
                CError.Compare(sc.IsCompiled, true, "IsCompiled");
                CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM");
            }
            catch (XmlSchemaException e)
            {
                _output.WriteLine(e.ToString());
                return;
            }
            Assert.True(false);
        }
        public void v8(object param0)
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                //after compile
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                sc.Compile();
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains("ns-d"), false, "Contains");
                CError.Compare(sc.Contains("ns-c"), false, "Contains");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");

                //before compile
                Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains("ns-d"), false, "Contains");
                CError.Compare(sc.Contains("ns-c"), false, "Contains");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Esempio n. 35
0
        public void v10()
        {
            bWarningCallback = false;
            bErrorCallback = false;

            XmlSchemaSet sc = new XmlSchemaSet();
            sc.XmlResolver = new XmlUrlResolver();
            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

            XmlSchema Schema1 = sc.Add(null, TestData._Root + "reprocess_v9_a.xsd");
            CError.Compare(sc.Count, 2, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 2, "Count after add/comp");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add/comp");
            //edit
            XmlSchemaImport imp = new XmlSchemaImport();
            imp.Namespace = "ns-a";
            imp.SchemaLocation = "reprocess_v9_a.xsd";
            Schema1.Includes.Add(imp);

            sc.Reprocess(Schema1);
            ValidateSchemaSet(sc, 2, false, 2, 1, 0, "Validation after edit/reprocess");
            CError.Compare(bWarningCallback, false, "Warning repr");
            CError.Compare(bErrorCallback, true, "Error repr");

            sc.Compile();
            ValidateSchemaSet(sc, 2, false, 2, 1, 0, "Validation after comp/reprocess");
            CError.Compare(bWarningCallback, false, "Warning comp");
            CError.Compare(bErrorCallback, true, "Error comp");
            CError.Compare(Schema1.IsCompiled, false, "IsCompiled on SOM");

            return;
        }
        public void v9()
        {
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(null, Path.Combine(TestData._Root, "import_v16_b.xsd"));

                //before compile
                XmlSchema parent = sc.Add(null, Path.Combine(TestData._Root, "import_v16_a.xsd"));
                sc.Compile();
                sc.RemoveRecursive(parent);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains("ns-b"), true, "Contains");

                //after compile
                parent = sc.Add(null, Path.Combine(TestData._Root, "import_v16_a.xsd"));
                sc.RemoveRecursive(parent);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains("ns-b"), true, "Contains");

                return;
            }
            catch (XmlSchemaException e)
            {
                _output.WriteLine("Exception : " + e.Message);
            }
            Assert.True(false);
        }
 public static XmlSchemaComplexType GetTypedDataSetSchema(XmlSchemaSet xs)
 {
     UserWorkingProfileDS userWorkingProfileDS = new UserWorkingProfileDS();
     XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType();
     XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
     XmlSchemaAny xmlSchemaAny = new XmlSchemaAny();
     xmlSchemaAny.Namespace = userWorkingProfileDS.Namespace;
     xmlSchemaSequence.Items.Add(xmlSchemaAny);
     xmlSchemaComplexType.Particle = xmlSchemaSequence;
     XmlSchema schemaSerializable = userWorkingProfileDS.GetSchemaSerializable();
     XmlSchemaComplexType result;
     if (xs.Contains(schemaSerializable.TargetNamespace))
     {
         MemoryStream memoryStream = new MemoryStream();
         MemoryStream memoryStream2 = new MemoryStream();
         try
         {
             schemaSerializable.Write(memoryStream);
             IEnumerator enumerator = xs.Schemas(schemaSerializable.TargetNamespace).GetEnumerator();
             while (enumerator.MoveNext())
             {
                 XmlSchema xmlSchema = (XmlSchema)enumerator.Current;
                 memoryStream2.SetLength(0L);
                 xmlSchema.Write(memoryStream2);
                 if (memoryStream.Length == memoryStream2.Length)
                 {
                     memoryStream.Position = 0L;
                     memoryStream2.Position = 0L;
                     while (memoryStream.Position != memoryStream.Length && memoryStream.ReadByte() == memoryStream2.ReadByte())
                     {
                     }
                     if (memoryStream.Position == memoryStream.Length)
                     {
                         result = xmlSchemaComplexType;
                         return result;
                     }
                 }
             }
         }
         finally
         {
             if (memoryStream != null)
             {
                 memoryStream.Close();
             }
             if (memoryStream2 != null)
             {
                 memoryStream2.Close();
             }
         }
     }
     xs.Add(schemaSerializable);
     result = xmlSchemaComplexType;
     return result;
 }
Esempio n. 38
0
        public void v4()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
            XmlSchema Schema = XmlSchema.Read(new StreamReader(new FileStream(TestData._FileXSD1, FileMode.Open, FileAccess.Read)), null);
            XmlSchema SchemaNew1 = sc.Add(Schema);
            XmlSchema SchemaNew2 = sc.Add("schema1.xsd", TestData._FileXSD1);

            // both schemas are added but they are dup
            Assert.Equal(sc.Count, 2);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, false);

            // check its not the same schema as first
            Assert.Equal(Schema == SchemaNew1, true);
            Assert.Equal(Schema == SchemaNew2, false);

            try
            {
                sc.Compile();
            }
            catch (XmlSchemaException)
            {
                Assert.Equal(sc.Count, 2);
                Assert.Equal(sc.Contains(SchemaNew1), true);
                Assert.Equal(sc.Contains(SchemaNew2), true);
                Assert.Equal(sc.IsCompiled, false);
                return;
            }

            Assert.True(false);
        }