// .NET C# cannot have types with same name in the Codenamespace. If that happens a digit is appended to the typename. // Eg. CoreComponents and UnqualifiedDataTypes both have "IdentifierType", one gets named "IdentifierType1" :-( // Solution: Prepend types in CoreComponents with "cctscct" and modify references in UnqualifiedComponents public static void ResolveTypeNameClashesByRenaming(XmlSchemaSet schemaSet) { string ccts_cctPrefix = "cctscct"; XmlSchema coreCompSchema = schemaSet.Schemas(Constants.CoreComponentTypeSchemaModuleTargetNamespace).OfType<XmlSchema>().Single(); XmlSchema unqualSchema = schemaSet.Schemas(Constants.UnqualifiedDataTypesTargetNamespace).OfType<XmlSchema>().Single(); foreach (var complexType in coreCompSchema.Items.OfType<XmlSchemaComplexType>()) { complexType.Name = ccts_cctPrefix + complexType.Name; complexType.IsAbstract = true; // Make it abstract as well. Ain't gonna use the base, only the one derived from this type. } foreach (var complexType in unqualSchema.Items.OfType<XmlSchemaComplexType>() .Where(t => t.BaseXmlSchemaType.QualifiedName.Namespace.Equals(Constants.CoreComponentTypeSchemaModuleTargetNamespace))) { var name = new XmlQualifiedName(ccts_cctPrefix + complexType.BaseXmlSchemaType.QualifiedName.Name, complexType.BaseXmlSchemaType.QualifiedName.Namespace); var content = complexType.ContentModel as XmlSchemaSimpleContent; if (content.Content is XmlSchemaSimpleContentRestriction) { (content.Content as XmlSchemaSimpleContentRestriction).BaseTypeName = name; } else if (content.Content is XmlSchemaSimpleContentExtension) { (content.Content as XmlSchemaSimpleContentExtension).BaseTypeName = name; } } schemaSet.Reprocess(coreCompSchema); schemaSet.Reprocess(unqualSchema); }
private static void AddDefaultTypedDatasetType(XmlSchemaSet schemas, XmlSchema datasetSchema, string localName, string ns) { XmlSchemaComplexType item = new XmlSchemaComplexType { Name = localName, Particle = new XmlSchemaSequence() }; XmlSchemaAny any = new XmlSchemaAny { Namespace = (datasetSchema.TargetNamespace == null) ? string.Empty : datasetSchema.TargetNamespace }; ((XmlSchemaSequence) item.Particle).Items.Add(any); schemas.Add(datasetSchema); XmlSchema schema = SchemaHelper.GetSchema(ns, schemas); schema.Items.Add(item); schemas.Reprocess(datasetSchema); schemas.Reprocess(schema); }
internal static void AddDefaultXmlType(XmlSchemaSet schemas, string localName, string ns) { XmlSchemaComplexType defaultXmlType = CreateAnyType(); defaultXmlType.Name = localName; XmlSchema schema = SchemaHelper.GetSchema(ns, schemas); schema.Items.Add(defaultXmlType); schemas.Reprocess(schema); }
public static XmlQualifiedName EnsureProbeMatchSchema(DiscoveryVersion discoveryVersion, XmlSchemaSet schemaSet) { Fx.Assert(schemaSet != null, "The schemaSet must be non null."); Fx.Assert(discoveryVersion != null, "The discoveryVersion must be non null."); // ensure that EPR is added to the schema. if (discoveryVersion == DiscoveryVersion.WSDiscoveryApril2005 || discoveryVersion == DiscoveryVersion.WSDiscoveryCD1) { EndpointAddressAugust2004.GetSchema(schemaSet); } else if (discoveryVersion == DiscoveryVersion.WSDiscovery11) { EndpointAddress10.GetSchema(schemaSet); } else { Fx.Assert("The discoveryVersion is not supported."); } // do not add/find Probe related schema items SchemaTypes typesFound = SchemaTypes.ProbeType | SchemaTypes.ResolveType; SchemaElements elementsFound = SchemaElements.None; XmlSchema discoverySchema = null; ICollection discoverySchemas = schemaSet.Schemas(discoveryVersion.Namespace); if ((discoverySchemas == null) || (discoverySchemas.Count == 0)) { discoverySchema = CreateSchema(discoveryVersion); AddImport(discoverySchema, discoveryVersion.Implementation.WsaNamespace); schemaSet.Add(discoverySchema); } else { foreach (XmlSchema schema in discoverySchemas) { discoverySchema = schema; if (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ProbeMatchType)) { typesFound |= SchemaTypes.ProbeMatchType; break; } LocateSchemaTypes(discoveryVersion, schema, ref typesFound); LocateSchemaElements(discoveryVersion, schema, ref elementsFound); } } if ((typesFound & SchemaTypes.ProbeMatchType) != SchemaTypes.ProbeMatchType) { AddSchemaTypes(discoveryVersion, typesFound, discoverySchema); AddElements(discoveryVersion, elementsFound, discoverySchema); schemaSet.Reprocess(discoverySchema); } return discoveryVersion.Implementation.QualifiedNames.ProbeMatchType; }
static internal void AddTypeToSchema(XmlSchemaType type, XmlSchema schema, XmlSchemaSet schemaSet) { XmlSchemaType existingType = (XmlSchemaType)schema.SchemaTypes[new XmlQualifiedName(type.Name, schema.TargetNamespace)]; if (existingType != null) { if (existingType == type) return; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxConflictingGlobalType, type.Name, schema.TargetNamespace))); } schema.Items.Add(type); schemaSet.Reprocess(schema); }
public void v1() { XmlSchemaSet sc = new XmlSchemaSet(); try { sc.Reprocess(null); } catch (ArgumentNullException e) { _output.WriteLine(e.ToString()); CError.Compare(sc.Count, 0, "AddCount"); CError.Compare(sc.IsCompiled, false, "AddIsCompiled"); return; } Assert.True(false); }
internal static void AddTypeToSchema(XmlSchemaType type, System.Xml.Schema.XmlSchema schema, XmlSchemaSet schemaSet) { XmlSchemaType type2 = (XmlSchemaType) schema.SchemaTypes[new XmlQualifiedName(type.Name, schema.TargetNamespace)]; if (type2 != null) { if (type2 != type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxConflictingGlobalType", new object[] { type.Name, schema.TargetNamespace }))); } } else { schema.Items.Add(type); schemaSet.Reprocess(schema); } }
static internal void AddElementToSchema(XmlSchemaElement element, XmlSchema schema, XmlSchemaSet schemaSet) { XmlSchemaElement existingElement = (XmlSchemaElement)schema.Elements[new XmlQualifiedName(element.Name, schema.TargetNamespace)]; if (existingElement != null) { if (element.SchemaType == existingElement.SchemaType && element.SchemaTypeName == existingElement.SchemaTypeName) return; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxConflictingGlobalElement, element.Name, schema.TargetNamespace, GetTypeName(element), GetTypeName(existingElement)))); } schema.Items.Add(element); if (!element.SchemaTypeName.IsEmpty) AddImportToSchema(element.SchemaTypeName.Namespace, schema); schemaSet.Reprocess(schema); }
private static void AddDefaultDatasetType(XmlSchemaSet schemas, string localName, string ns) { XmlSchemaComplexType item = new XmlSchemaComplexType { Name = localName, Particle = new XmlSchemaSequence() }; XmlSchemaElement element = new XmlSchemaElement { RefName = new XmlQualifiedName("schema", "http://www.w3.org/2001/XMLSchema") }; ((XmlSchemaSequence) item.Particle).Items.Add(element); XmlSchemaAny any = new XmlSchemaAny(); ((XmlSchemaSequence) item.Particle).Items.Add(any); XmlSchema schema = SchemaHelper.GetSchema(ns, schemas); schema.Items.Add(item); schemas.Reprocess(schema); }
internal static void AddElementToSchema(XmlSchemaElement element, System.Xml.Schema.XmlSchema schema, XmlSchemaSet schemaSet) { XmlSchemaElement element2 = (XmlSchemaElement) schema.Elements[new XmlQualifiedName(element.Name, schema.TargetNamespace)]; if (element2 != null) { if ((element.SchemaType != element2.SchemaType) || (element.SchemaTypeName != element2.SchemaTypeName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxConflictingGlobalElement", new object[] { element.Name, schema.TargetNamespace, GetTypeName(element), GetTypeName(element2) }))); } } else { schema.Items.Add(element); if (!element.SchemaTypeName.IsEmpty) { AddImportToSchema(element.SchemaTypeName.Namespace, schema); } schemaSet.Reprocess(schema); } }
public void v1(String testDir, String testFile, int expCount, int expCountGT, int expCountGE, int expCountGA) { Initialize(); string xsd = Path.Combine(path, testDir, testFile); XmlSchemaSet ss = new XmlSchemaSet(); XmlSchema Schema = XmlSchema.Read(XmlReader.Create(xsd), ValidationCallback); ss.XmlResolver = new XmlUrlResolver(); XmlSchema Schema1 = ss.Add(Schema); ValidateSchemaSet(ss, expCount, false, 0, 0, 0, "Validation after add"); ValidateWithSchemaInfo(ss); ss.Compile(); ValidateSchemaSet(ss, expCount, true, expCountGT, expCountGE, expCountGA, "Validation after add/comp"); ValidateWithSchemaInfo(ss); XmlSchema Schema2 = null; foreach (XmlSchema schema in ss.Schemas()) Schema2 = ss.Reprocess(schema); ValidateSchemaSet(ss, expCount, false, 1, 0, 0, "Validation after repr"); ValidateWithSchemaInfo(ss); ss.Compile(); ValidateSchemaSet(ss, expCount, true, expCountGT, expCountGE, expCountGA, "Validation after repr/comp"); ValidateWithSchemaInfo(ss); Assert.Equal(ss.RemoveRecursive(Schema), true); ValidateSchemaSet(ss, 0, false, 1, 0, 0, "Validation after remRec"); ValidateWithSchemaInfo(ss); ss.Compile(); ValidateSchemaSet(ss, 0, true, 0, 0, 0, "Validation after remRec/comp"); ValidateWithSchemaInfo(ss); return; }
public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet) { if (xmlSchemaSet == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSchemaSet"); } XmlQualifiedName eprType = EprType; XmlSchema eprSchema = GetEprSchema(); ICollection is2 = xmlSchemaSet.Schemas("http://schemas.xmlsoap.org/ws/2004/08/addressing"); if ((is2 == null) || (is2.Count == 0)) { xmlSchemaSet.Add(eprSchema); return eprType; } XmlSchema schema = null; foreach (XmlSchema schema3 in is2) { if (schema3.SchemaTypes.Contains(eprType)) { schema = null; break; } schema = schema3; } if (schema != null) { foreach (XmlQualifiedName name2 in eprSchema.Namespaces.ToArray()) { schema.Namespaces.Add(name2.Name, name2.Namespace); } foreach (XmlSchemaObject obj2 in eprSchema.Items) { schema.Items.Add(obj2); } xmlSchemaSet.Reprocess(schema); } return eprType; }
public void v112() { Initialize(); XmlSchemaSet set2 = new XmlSchemaSet(); set2.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); XmlSchema includedSchema = set2.Add(null, Path.Combine(TestData._Root, "bug382035a1.xsd")); set2.Compile(); XmlSchemaSet set = new XmlSchemaSet(); set.XmlResolver = new XmlUrlResolver(); set.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); XmlSchema mainSchema = set.Add(null, Path.Combine(TestData._Root, "bug382035a.xsd")); set.Compile(); XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, "bug382035a1.xsd")); XmlSchema reParsedInclude = XmlSchema.Read(r, new ValidationEventHandler(ValidationCallback)); ((XmlSchemaExternal)mainSchema.Includes[0]).Schema = reParsedInclude; set.Reprocess(mainSchema); set.Compile(); CError.Compare(warningCount, 0, "Warning Count mismatch!"); CError.Compare(errorCount, 0, "Error Count mismatch!"); return; }
public void v50() { bWarningCallback = false; bErrorCallback = false; XmlSchemaSet schemaSet = new XmlSchemaSet(); XmlSchema schema = new XmlSchema(); schemaSet.Add(schema); schema.TargetNamespace = "http://myns/"; //type XmlSchemaType schemaType = new XmlSchemaComplexType(); schemaType.Name = "MySimpleType"; schema.Items.Add(schemaType); schemaSet.Reprocess(schema); schemaSet.Compile(); //element XmlSchemaElement schemaElement = new XmlSchemaElement(); schemaElement.Name = "MyElement"; schema.Items.Add(schemaElement); schemaSet.Reprocess(schema); schemaSet.Compile(); //attribute XmlSchemaAttribute schemaAttribute = new XmlSchemaAttribute(); schemaAttribute.Name = "MyAttribute"; schema.Items.Add(schemaAttribute); schemaSet.Reprocess(schema); schemaSet.Compile(); schemaSet.Reprocess(schema); schemaSet.Compile(); schema.Items.Remove(schemaType);//what is the best way to remove it? schema.Items.Remove(schemaElement); schema.Items.Remove(schemaAttribute); schemaSet.Reprocess(schema); schemaSet.Compile(); schemaType = new XmlSchemaComplexType(); schemaType.Name = "MySimpleType"; schema.Items.Add(schemaType); schema.Items.Add(schemaElement); schema.Items.Add(schemaAttribute); schemaSet.Reprocess(schema); schemaSet.Compile(); CError.Compare(schemaSet.GlobalElements.Count, 1, "Element count mismatch!"); CError.Compare(schemaSet.GlobalAttributes.Count, 1, "Attributes count mismatch!"); CError.Compare(schemaSet.GlobalTypes.Count, 2, "Types count mismatch!"); return; }
public void v51(object param0, object param1, object param2, object param3) { bWarningCallback = false; bErrorCallback = false; string mainFile = TestData._Root + param0.ToString(); string include1 = TestData._Root + param1.ToString(); string include2 = TestData._Root + param2.ToString(); string xmlFile = TestData._Root + "bug382119.xml"; bool IsImport = (bool)param3; XmlSchemaSet set1 = new XmlSchemaSet(); set1.XmlResolver = new XmlUrlResolver(); set1.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); XmlSchema includedSchema = set1.Add(null, include1); set1.Compile(); XmlSchemaSet set = new XmlSchemaSet(); set.XmlResolver = new XmlUrlResolver(); set.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); XmlSchema mainSchema = set.Add(null, mainFile); set.Compile(); _output.WriteLine("First validation ***************"); XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); settings.ValidationType = ValidationType.Schema; settings.Schemas = set; XmlReader reader = XmlReader.Create(xmlFile, settings); while (reader.Read()) { } CError.Compare(bWarningCallback, false, "Warning count mismatch"); CError.Compare(bErrorCallback, true, "Error count mismatch"); if (IsImport == true) set.Remove(((XmlSchemaExternal)mainSchema.Includes[0]).Schema); _output.WriteLine("re-setting include"); XmlSchema reParsedInclude = LoadSchema(include2, include1); ((XmlSchemaExternal)mainSchema.Includes[0]).Schema = reParsedInclude; _output.WriteLine("Calling reprocess"); set.Reprocess(mainSchema); set.Compile(); bWarningCallback = false; bErrorCallback = false; _output.WriteLine("Second validation ***************"); settings.Schemas = set; reader = XmlReader.Create(xmlFile, settings); while (reader.Read()) { } CError.Compare(bWarningCallback, false, "Warning count mismatch"); CError.Compare(bErrorCallback, false, "Error count mismatch"); //Editing the include again _output.WriteLine("Re-adding include to set1"); XmlSchema reParsedInclude2 = LoadSchema(include1, include1); set1.Remove(includedSchema); set1.Add(reParsedInclude2); set1.Compile(); if (IsImport == true) set.Remove(((XmlSchemaExternal)mainSchema.Includes[0]).Schema); ((XmlSchemaExternal)mainSchema.Includes[0]).Schema = reParsedInclude2; set.Reprocess(mainSchema); set.Compile(); bWarningCallback = false; bErrorCallback = false; _output.WriteLine("Third validation, Expecting errors ***************"); settings.Schemas = set; reader = XmlReader.Create(xmlFile, settings); while (reader.Read()) { } CError.Compare(bWarningCallback, false, "Warning count mismatch"); CError.Compare(bErrorCallback, true, "Error count mismatch"); return; }
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 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; }
public void v3(object param0, object param1, object param2, object param3, object param4, object param5, object param6) { string ns1 = param0.ToString(); string ns2 = param3.ToString(); string type1 = param1.ToString(); string type2 = param2.ToString(); string type3 = param4.ToString(); string type4 = param5.ToString(); bool doCompile = (bool)param6; XmlSchema s1 = GetSchema(ns1, type1, type2); XmlSchema s2 = GetSchema(ns2, type3, type4); XmlSchemaSet ss1 = new XmlSchemaSet(); XmlSchemaSet ss2 = new XmlSchemaSet(); ss1.Add(s1); ss1.Compile(); ss2.Add(s2); if (doCompile) ss2.Compile(); // add one schemaset to another ss1.Add(ss2); if (!doCompile) ss1.Compile(); //Verify CError.Compare(ss1.GlobalTypes.Count, 5, "Types Count after add/comp"); //+1 for anyType CError.Compare(ss1.GlobalTypes.Contains(new XmlQualifiedName(type1, ns1)), true, "Contains1"); CError.Compare(ss1.GlobalTypes.Contains(new XmlQualifiedName(type2, ns1)), true, "Contains2"); CError.Compare(ss1.GlobalTypes.Contains(new XmlQualifiedName(type3, ns2)), true, "Contains3"); CError.Compare(ss1.GlobalTypes.Contains(new XmlQualifiedName(type4, ns2)), true, "Contains4"); //Now reprocess one schema and check ss1.Reprocess(s1); CError.Compare(ss1.GlobalTypes.Count, 3, "Types Count repr"); //+1 for anyType ss1.Compile(); CError.Compare(ss1.GlobalTypes.Count, 5, "Types Count repr/comp"); //+1 for anyType //Now Remove one schema and check ss1.Remove(s1); CError.Compare(ss1.GlobalTypes.Count, 3, "Types Count after remove"); ss1.Compile(); CError.Compare(ss1.GlobalTypes.Count, 3, "Types Count after rem/comp"); return; }
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; }
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 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; }
public static XmlQualifiedName EnsureProbeSchema(DiscoveryVersion discoveryVersion, XmlSchemaSet schemaSet) { Fx.Assert(schemaSet != null, "The schemaSet must be non null."); Fx.Assert(discoveryVersion != null, "The discoveryVersion must be non null."); // do not find/add ProbeMatch related schema items SchemaTypes typesFound = SchemaTypes.ProbeMatchType | SchemaTypes.ResolveType; SchemaElements elementsFound = SchemaElements.XAddrs | SchemaElements.MetadataVersion; XmlSchema discoverySchema = null; ICollection discoverySchemas = schemaSet.Schemas(discoveryVersion.Namespace); if ((discoverySchemas == null) || (discoverySchemas.Count == 0)) { discoverySchema = CreateSchema(discoveryVersion); schemaSet.Add(discoverySchema); } else { foreach (XmlSchema schema in discoverySchemas) { discoverySchema = schema; if (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.ProbeType)) { typesFound |= SchemaTypes.ProbeType; break; } LocateSchemaTypes(discoveryVersion, schema, ref typesFound); LocateSchemaElements(discoveryVersion, schema, ref elementsFound); } } if ((typesFound & SchemaTypes.ProbeType) != SchemaTypes.ProbeType) { AddSchemaTypes(discoveryVersion, typesFound, discoverySchema); AddElements(discoveryVersion, elementsFound, discoverySchema); schemaSet.Reprocess(discoverySchema); } return discoveryVersion.Implementation.QualifiedNames.ProbeType; }
public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet) { if (xmlSchemaSet == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSchemaSet"); XmlQualifiedName eprType = EprType; XmlSchema eprSchema = GetEprSchema(); ICollection schemas = xmlSchemaSet.Schemas(Addressing200408Strings.Namespace); if (schemas == null || schemas.Count == 0) xmlSchemaSet.Add(eprSchema); else { XmlSchema schemaToAdd = null; foreach (XmlSchema xmlSchema in schemas) { if (xmlSchema.SchemaTypes.Contains(eprType)) { schemaToAdd = null; break; } else schemaToAdd = xmlSchema; } if (schemaToAdd != null) { foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray()) schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace); foreach (XmlSchemaObject schemaObject in eprSchema.Items) schemaToAdd.Items.Add(schemaObject); xmlSchemaSet.Reprocess(schemaToAdd); } } return eprType; }
public static XmlQualifiedName EnsureAppSequenceSchema(DiscoveryVersion discoveryVersion, XmlSchemaSet schemaSet) { Fx.Assert(schemaSet != null, "The schemaSet must be non null."); Fx.Assert(discoveryVersion != null, "The discoveryVersion must be non null."); bool add = true; XmlSchema discoverySchema = null; ICollection discoverySchemas = schemaSet.Schemas(discoveryVersion.Namespace); if ((discoverySchemas == null) || (discoverySchemas.Count == 0)) { discoverySchema = CreateSchema(discoveryVersion); schemaSet.Add(discoverySchema); } else { foreach (XmlSchema schema in discoverySchemas) { discoverySchema = schema; if (schema.SchemaTypes.Contains(discoveryVersion.Implementation.QualifiedNames.AppSequenceType)) { add = false; break; } } } if (add) { AddAppSequenceType(discoveryVersion, discoverySchema); schemaSet.Reprocess(discoverySchema); } return discoveryVersion.Implementation.QualifiedNames.AppSequenceType; }
public static FxtLog Run(XmlSchemaSet schemas, XElement trafo, interpreter i) { var trafos = new List<IFxtTransformation>(); var log = new FxtLog(); // Compile if necessary if (!schemas.IsCompiled) schemas.Compile(); if (trafo==null) return log; // Interpret trafo i(schemas, trafo,log,trafos); // Execute trafos foreach (var x in trafos) x.Run(); // Re-compile foreach (var x in schemas.XmlSchemas()) schemas.Reprocess(x); schemas.Compile(); return log; }
public void v2(object param0, object param1, object param2, object param3, object param4, object param5) { string ns1 = param0.ToString(); string ns2 = param3.ToString(); string type1 = param1.ToString(); string type2 = param2.ToString(); string type3 = param4.ToString(); string type4 = param5.ToString(); XmlSchema s1 = GetSchema(ns1, type1, type2); XmlSchema s2 = GetSchema(ns2, type3, type4); XmlSchemaSet ss = new XmlSchemaSet(); ss.Add(s1); CError.Compare(ss.GlobalTypes.Count, 0, "Types Count after add"); ss.Compile(); ss.Add(s2); CError.Compare(ss.GlobalTypes.Count, 3, "Types Count after add/compile"); //+1 for anyType ss.Compile(); //Verify CError.Compare(ss.GlobalTypes.Count, 5, "Types Count after add/compile/add/compile"); //+1 for anyType CError.Compare(ss.GlobalTypes.Contains(new XmlQualifiedName(type1, ns1)), true, "Contains1"); CError.Compare(ss.GlobalTypes.Contains(new XmlQualifiedName(type2, ns1)), true, "Contains2"); CError.Compare(ss.GlobalTypes.Contains(new XmlQualifiedName(type3, ns2)), true, "Contains3"); CError.Compare(ss.GlobalTypes.Contains(new XmlQualifiedName(type4, ns2)), true, "Contains4"); //Now reprocess one schema and check ss.Reprocess(s1); CError.Compare(ss.GlobalTypes.Count, 3, "Types Count after repr"); //+1 for anyType ss.Compile(); CError.Compare(ss.GlobalTypes.Count, 5, "Types Count after repr/comp"); //+1 for anyType //Now Remove one schema and check ss.Remove(s1); CError.Compare(ss.GlobalTypes.Count, 3, "Types Count after remove"); ss.Compile(); CError.Compare(ss.GlobalTypes.Count, 3, "Types Count after remove/comp"); return; }
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); }
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); }
internal XmlSchemaSet InferSchema1(XmlReader instanceDocument, XmlSchemaSet schemas) { if (instanceDocument == null) { throw new ArgumentNullException("instanceDocument"); } this.rootSchema = null; xtr = instanceDocument; schemas.Compile(); this.schemaSet = schemas; //schemas = new Hashtable(); //while(xtr.Read()) while (xtr.NodeType != XmlNodeType.Element && xtr.Read()) ; if (xtr.NodeType == XmlNodeType.Element) { //Create and process the root element TargetNamespace = xtr.NamespaceURI; if ( xtr.NamespaceURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } XmlSchemaElement xse = null; foreach (XmlSchemaElement elem in schemas.GlobalElements.Values) { if (elem.Name == xtr.LocalName && elem.QualifiedName.Namespace == xtr.NamespaceURI) { rootSchema = elem.Parent as XmlSchema; xse = elem; break; } } if (rootSchema == null) { //rootSchema = CreateXmlSchema(xtr.NamespaceURI); xse = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, null, null, -1); } else { //bRefine = true; InferElement(xse, false, rootSchema); } /* foreach (ReplaceList listItem in schemaList) { if (listItem.position < listItem.col.Count) { XmlSchemaElement particle = listItem.col[listItem.position] as XmlSchemaElement; if (particle != null && (particle.RefName.Namespace == XmlSchema.Namespace)) { XmlSchemaAny any = new XmlSchemaAny(); if (particle.MaxOccurs != 1) { any.MaxOccurs = particle.MaxOccurs; } if (particle.MinOccurs != 1) { any.MinOccurs = particle.MinOccurs; } any.ProcessContents = XmlSchemaContentProcessing.Skip; any.MinOccurs = decimal.Zero; any.Namespace = particle.RefName.Namespace; listItem.col[listItem.position] = any; } } }*/ foreach(String prefix in this.NamespaceManager) { if (!prefix.Equals("xml") && !prefix.Equals("xmlns")) { String ns = this.NamespaceManager.LookupNamespace(this.nametable.Get(prefix)); if (ns.Length != 0) { //Do not add xmlns="" rootSchema.Namespaces.Add(prefix, ns); } } } Debug.Assert(this.rootSchema != null, "rootSchema is null"); schemas.Reprocess(rootSchema); schemas.Compile(); //break; } else { throw new XmlSchemaInferenceException(Res.SchInf_NoElement, 0, 0); } return schemas; }
public void v12a() { using (XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, @"bug264908_v1.xsd"))) { XmlSchema s = XmlSchema.Read(r, null); using (XmlReader r2 = XmlReader.Create(Path.Combine(TestData._Root, @"bug264908_v1a.xsd"))) { XmlSchema s2 = XmlSchema.Read(r2, null); XmlSchemaSet set = new XmlSchemaSet(); set.XmlResolver = null; set.Add(s); set.Add(s2); set.Compile(); foreach (XmlSchema schema in set.Schemas()) set.Reprocess(schema); } } }