2 // System.Xml.Serialization.XmlSchemaExporter
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // Copyright (C) Tim Coleman, 2002
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Xml.Schema;
34 using System.Collections;
36 namespace System.Xml.Serialization {
37 public class XmlSchemaExporter {
42 Hashtable exportedMaps = new Hashtable();
43 Hashtable exportedElements = new Hashtable();
44 bool encodedFormat = false;
51 public XmlSchemaExporter (XmlSchemas schemas)
53 this.schemas = schemas;
56 internal XmlSchemaExporter (XmlSchemas schemas, bool encodedFormat)
58 this.encodedFormat = encodedFormat;
59 this.schemas = schemas;
62 #endregion // Constructors
67 public string ExportAnyType (string ns)
69 throw new NotImplementedException ();
72 public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
74 ExportMembersMapping (xmlMembersMapping, true);
82 void ExportMembersMapping (XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
84 ClassMap cmap = (ClassMap) xmlMembersMapping.ObjectMap;
86 if (xmlMembersMapping.HasWrapperElement && exportEnclosingType)
88 XmlSchema schema = GetSchema (xmlMembersMapping.Namespace);
89 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
91 XmlSchemaSequence particle;
92 XmlSchemaAnyAttribute anyAttribute;
93 ExportMembersMapSchema (schema, cmap, null, stype.Attributes, out particle, out anyAttribute);
94 stype.Particle = particle;
95 stype.AnyAttribute = anyAttribute;
99 stype.Name = xmlMembersMapping.ElementName;
100 schema.Items.Add (stype);
104 XmlSchemaElement selem = new XmlSchemaElement ();
105 selem.Name = xmlMembersMapping.ElementName;
106 selem.SchemaType = stype;
107 schema.Items.Add (selem);
112 ICollection members = cmap.ElementMembers;
115 foreach (XmlTypeMapMemberElement member in members)
117 if (member is XmlTypeMapMemberAnyElement && member.TypeData.IsListType)
119 XmlSchema mschema = GetSchema (xmlMembersMapping.Namespace);
120 XmlSchemaParticle par = GetSchemaArrayElement (mschema, member.ElementInfo);
121 if (par is XmlSchemaAny)
123 XmlSchemaComplexType ct = FindComplexType (mschema.Items, "any");
124 if (ct != null) continue;
126 ct = new XmlSchemaComplexType ();
129 XmlSchemaSequence seq = new XmlSchemaSequence ();
132 mschema.Items.Add (ct);
138 XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) member.ElementInfo [0];
143 schema = GetSchema (xmlMembersMapping.Namespace);
144 ImportNamespace (schema, XmlSerializer.EncodingNamespace);
147 schema = GetSchema (einfo.Namespace);
150 XmlSchemaElement exe = FindElement (schema.Items, einfo.ElementName);
151 XmlSchemaElement elem;
153 Type memType = member.GetType();
154 if (member is XmlTypeMapMemberFlatList)
155 throw new InvalidOperationException ("Unwrapped arrays not supported as parameters");
156 else if (memType == typeof(XmlTypeMapMemberElement))
157 elem = (XmlSchemaElement) GetSchemaElement (schema, einfo, member.DefaultValue, false);
159 elem = (XmlSchemaElement) GetSchemaElement (schema, einfo, false);
161 // In encoded format, the schema elements are not needed
163 schema.Items.Add (elem);
167 if (exe.SchemaTypeName.Equals (elem.SchemaTypeName))
168 schema.Items.Remove (elem);
171 string s = "The XML element named '" + einfo.ElementName + "' ";
172 s += "from namespace '" + schema.TargetNamespace + "' references distinct types " + elem.SchemaTypeName.Name + " and " + exe.SchemaTypeName.Name + ". ";
173 s += "Use XML attributes to specify another XML name or namespace for the element or types.";
174 throw new InvalidOperationException (s);
185 public XmlQualifiedName ExportTypeMapping (XmlMembersMapping xmlMembersMapping)
187 throw new NotImplementedException ();
190 public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
192 if (!xmlTypeMapping.IncludeInSchema) return;
193 if (IsElementExported (xmlTypeMapping)) return;
197 ExportClassSchema (xmlTypeMapping);
198 XmlSchema schema = GetSchema (xmlTypeMapping.XmlTypeNamespace);
199 ImportNamespace (schema, XmlSerializer.EncodingNamespace);
203 XmlSchema schema = GetSchema (xmlTypeMapping.Namespace);
204 XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (null, xmlTypeMapping.TypeData);
205 einfo.Namespace = xmlTypeMapping.Namespace;
206 einfo.ElementName = xmlTypeMapping.ElementName;
207 if (xmlTypeMapping.TypeData.IsComplexType)
208 einfo.MappedType = xmlTypeMapping;
209 einfo.IsNullable = false;
210 schema.Items.Add (GetSchemaElement (schema, einfo, false));
211 SetElementExported (xmlTypeMapping);
217 void ExportClassSchema (XmlTypeMapping map)
219 if (IsMapExported (map)) return;
220 SetMapExported (map);
222 if (map.TypeData.Type == typeof(object))
224 foreach (XmlTypeMapping dmap in map.DerivedTypes)
225 if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
229 XmlSchema schema = GetSchema (map.XmlTypeNamespace);
230 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
231 stype.Name = map.XmlType;
232 schema.Items.Add (stype);
234 ClassMap cmap = (ClassMap)map.ObjectMap;
236 if (cmap.HasSimpleContent)
238 XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent ();
239 stype.ContentModel = simple;
240 XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension ();
241 simple.Content = ext;
242 XmlSchemaSequence particle;
243 XmlSchemaAnyAttribute anyAttribute;
244 ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
245 ext.AnyAttribute = anyAttribute;
246 if (map.BaseMap == null)
247 ext.BaseTypeName = cmap.SimpleContentBaseType;
249 ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
250 ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
251 ExportClassSchema (map.BaseMap);
254 else if (map.BaseMap != null && map.BaseMap.IncludeInSchema)
256 XmlSchemaComplexContent cstype = new XmlSchemaComplexContent ();
257 XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension ();
258 ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
259 cstype.Content = ext;
260 stype.ContentModel = cstype;
262 XmlSchemaSequence particle;
263 XmlSchemaAnyAttribute anyAttribute;
264 ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
265 ext.Particle = particle;
266 ext.AnyAttribute = anyAttribute;
267 stype.IsMixed = HasMixedContent (map);
268 cstype.IsMixed = BaseHasMixedContent (map);
270 ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
271 ExportClassSchema (map.BaseMap);
275 XmlSchemaSequence particle;
276 XmlSchemaAnyAttribute anyAttribute;
277 ExportMembersMapSchema (schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute);
278 stype.Particle = particle;
279 stype.AnyAttribute = anyAttribute;
280 stype.IsMixed = cmap.XmlTextCollector != null;
283 foreach (XmlTypeMapping dmap in map.DerivedTypes)
284 if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
287 bool BaseHasMixedContent (XmlTypeMapping map)
289 ClassMap cmap = (ClassMap)map.ObjectMap;
290 return (cmap.XmlTextCollector != null && (map.BaseMap != null && DefinedInBaseMap (map.BaseMap, cmap.XmlTextCollector)));
293 bool HasMixedContent (XmlTypeMapping map)
295 ClassMap cmap = (ClassMap)map.ObjectMap;
296 return (cmap.XmlTextCollector != null && (map.BaseMap == null || !DefinedInBaseMap (map.BaseMap, cmap.XmlTextCollector)));
299 void ExportMembersMapSchema (XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute)
302 XmlSchemaSequence seq = new XmlSchemaSequence ();
304 ICollection members = map.ElementMembers;
305 if (members != null && !map.HasSimpleContent)
307 foreach (XmlTypeMapMemberElement member in members)
309 if (baseMap != null && DefinedInBaseMap (baseMap, member)) continue;
311 Type memType = member.GetType();
312 if (memType == typeof(XmlTypeMapMemberFlatList))
314 XmlSchemaParticle part = GetSchemaArrayElement (schema, member.ElementInfo);
315 if (part != null) seq.Items.Add (part);
317 else if (memType == typeof(XmlTypeMapMemberAnyElement))
319 seq.Items.Add (GetSchemaArrayElement (schema, member.ElementInfo));
321 else if (memType == typeof(XmlTypeMapMemberElement))
323 XmlSchemaParticle elem = GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, true);
325 seq.Items.Add (elem);
329 seq.Items.Add (GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo [0], true));
334 if (seq.Items.Count > 0)
339 ICollection attributes = map.AttributeMembers;
340 if (attributes != null)
342 foreach (XmlTypeMapMemberAttribute attr in attributes) {
343 if (baseMap != null && DefinedInBaseMap (baseMap, attr)) continue;
344 outAttributes.Add (GetSchemaAttribute (schema, attr, true));
348 XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;
349 if (anyAttrMember != null)
350 anyAttribute = new XmlSchemaAnyAttribute ();
355 XmlSchemaElement FindElement (XmlSchemaObjectCollection col, string name)
357 foreach (XmlSchemaObject ob in col)
359 XmlSchemaElement elem = ob as XmlSchemaElement;
360 if (elem != null && elem.Name == name) return elem;
365 XmlSchemaComplexType FindComplexType (XmlSchemaObjectCollection col, string name)
367 foreach (XmlSchemaObject ob in col)
369 XmlSchemaComplexType ctype = ob as XmlSchemaComplexType;
370 if (ctype != null && ctype.Name == name) return ctype;
375 XmlSchemaAttribute GetSchemaAttribute (XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo, bool isTypeMember)
377 XmlSchemaAttribute sat = new XmlSchemaAttribute ();
378 if (attinfo.DefaultValue != System.DBNull.Value) sat.DefaultValue = XmlCustomFormatter.ToXmlString (attinfo.TypeData, attinfo.DefaultValue);
380 ImportNamespace (currentSchema, attinfo.Namespace);
382 XmlSchema memberSchema;
383 if (attinfo.Namespace.Length == 0 && attinfo.Form != XmlSchemaForm.Qualified)
384 memberSchema = currentSchema;
386 memberSchema = GetSchema (attinfo.Namespace);
388 if (currentSchema == memberSchema || encodedFormat)
390 sat.Name = attinfo.AttributeName;
391 if (isTypeMember) sat.Form = attinfo.Form;
392 if (attinfo.TypeData.SchemaType == SchemaTypes.Enum)
394 ImportNamespace (currentSchema, attinfo.DataTypeNamespace);
395 ExportEnumSchema (attinfo.MappedType);
396 sat.SchemaTypeName = new XmlQualifiedName (attinfo.TypeData.XmlType, attinfo.DataTypeNamespace);;
398 else if (attinfo.TypeData.SchemaType == SchemaTypes.Array && TypeTranslator.IsPrimitive (attinfo.TypeData.ListItemType))
400 sat.SchemaType = GetSchemaSimpleListType (attinfo.TypeData);
403 sat.SchemaTypeName = new XmlQualifiedName (attinfo.TypeData.XmlType, attinfo.DataTypeNamespace);;
407 sat.RefName = new XmlQualifiedName (attinfo.AttributeName, attinfo.Namespace);
408 foreach (XmlSchemaObject ob in memberSchema.Items)
409 if (ob is XmlSchemaAttribute && ((XmlSchemaAttribute)ob).Name == attinfo.AttributeName)
412 memberSchema.Items.Add (GetSchemaAttribute (memberSchema, attinfo, false));
417 XmlSchemaParticle GetSchemaElement (XmlSchema currentSchema, XmlTypeMapElementInfo einfo, bool isTypeMember)
419 return GetSchemaElement (currentSchema, einfo, System.DBNull.Value, isTypeMember);
422 XmlSchemaParticle GetSchemaElement (XmlSchema currentSchema, XmlTypeMapElementInfo einfo, object defaultValue, bool isTypeMember)
424 if (einfo.IsTextElement) return null;
426 if (einfo.IsUnnamedAnyElement)
428 XmlSchemaAny any = new XmlSchemaAny ();
434 XmlSchemaElement selem = new XmlSchemaElement ();
439 selem.MinOccurs = einfo.IsNullable ? 1 : 0;
441 if ((einfo.TypeData.IsValueType && einfo.Member != null && !einfo.Member.IsOptionalValueType) || encodedFormat)
445 XmlSchema memberSchema = null;
449 memberSchema = GetSchema (einfo.Namespace);
450 ImportNamespace (currentSchema, einfo.Namespace);
453 if (currentSchema == memberSchema || encodedFormat || !isTypeMember)
455 if (isTypeMember) selem.IsNillable = einfo.IsNullable;
456 selem.Name = einfo.ElementName;
458 if (defaultValue != System.DBNull.Value)
459 selem.DefaultValue = XmlCustomFormatter.ToXmlString (einfo.TypeData, defaultValue);
461 if (einfo.Form != XmlSchemaForm.Qualified)
462 selem.Form = einfo.Form;
464 switch (einfo.TypeData.SchemaType)
466 case SchemaTypes.XmlNode:
467 selem.SchemaType = GetSchemaXmlNodeType ();
470 case SchemaTypes.XmlSerializable:
471 selem.SchemaType = GetSchemaXmlSerializableType ();
474 case SchemaTypes.Enum:
475 selem.SchemaTypeName = new XmlQualifiedName (einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace);
476 ImportNamespace (currentSchema, einfo.MappedType.XmlTypeNamespace);
477 ExportEnumSchema (einfo.MappedType);
480 case SchemaTypes.Array:
481 XmlQualifiedName atypeName = ExportArraySchema (einfo.MappedType, currentSchema.TargetNamespace);
482 selem.SchemaTypeName = atypeName;
483 ImportNamespace (currentSchema, atypeName.Namespace);
486 case SchemaTypes.Class:
487 if (einfo.MappedType.TypeData.Type != typeof(object)) {
488 selem.SchemaTypeName = new XmlQualifiedName (einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace);
489 ImportNamespace (currentSchema, einfo.MappedType.XmlTypeNamespace);
491 else if (encodedFormat)
492 selem.SchemaTypeName = new XmlQualifiedName (einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace);
494 ExportClassSchema (einfo.MappedType);
497 case SchemaTypes.Primitive:
498 selem.SchemaTypeName = new XmlQualifiedName (einfo.TypeData.XmlType, einfo.DataTypeNamespace);;
504 selem.RefName = new XmlQualifiedName (einfo.ElementName, einfo.Namespace);
505 foreach (XmlSchemaObject ob in memberSchema.Items)
506 if (ob is XmlSchemaElement && ((XmlSchemaElement)ob).Name == einfo.ElementName)
509 memberSchema.Items.Add (GetSchemaElement (memberSchema, einfo, defaultValue, false));
514 void ImportNamespace (XmlSchema schema, string ns)
516 if (ns == "" || ns == schema.TargetNamespace || ns == XmlSchema.Namespace) return;
518 foreach (XmlSchemaObject sob in schema.Includes)
519 if ((sob is XmlSchemaImport) && ((XmlSchemaImport)sob).Namespace == ns) return;
521 XmlSchemaImport imp = new XmlSchemaImport ();
523 schema.Includes.Add (imp);
526 bool DefinedInBaseMap (XmlTypeMapping map, XmlTypeMapMember member)
528 if (((ClassMap)map.ObjectMap).FindMember (member.Name) != null)
530 else if (map.BaseMap != null)
531 return DefinedInBaseMap (map.BaseMap, member);
536 XmlSchemaType GetSchemaXmlNodeType ()
538 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
539 stype.IsMixed = true;
540 XmlSchemaSequence seq = new XmlSchemaSequence ();
541 seq.Items.Add (new XmlSchemaAny ());
542 stype.Particle = seq;
546 XmlSchemaType GetSchemaXmlSerializableType ()
548 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
549 XmlSchemaSequence seq = new XmlSchemaSequence ();
550 XmlSchemaElement selem = new XmlSchemaElement ();
551 selem.RefName = new XmlQualifiedName ("schema",XmlSchema.Namespace);
552 seq.Items.Add (selem);
553 seq.Items.Add (new XmlSchemaAny ());
554 stype.Particle = seq;
558 XmlSchemaSimpleType GetSchemaSimpleListType (TypeData typeData)
560 XmlSchemaSimpleType stype = new XmlSchemaSimpleType ();
561 XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList ();
562 TypeData itemTypeData = TypeTranslator.GetTypeData (typeData.ListItemType);
563 list.ItemTypeName = new XmlQualifiedName (itemTypeData.XmlType, XmlSchema.Namespace);
564 stype.Content = list;
568 XmlSchemaParticle GetSchemaArrayElement (XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
570 int numInfos = infos.Count;
571 if (numInfos > 0 && ((XmlTypeMapElementInfo)infos[0]).IsTextElement) numInfos--;
572 if (numInfos == 0) return null;
576 XmlSchemaParticle selem = GetSchemaElement (currentSchema, (XmlTypeMapElementInfo) infos[infos.Count-1], true);
577 selem.MinOccursString = "0";
578 selem.MaxOccursString = "unbounded";
583 XmlSchemaChoice schoice = new XmlSchemaChoice ();
584 schoice.MinOccursString = "0";
585 schoice.MaxOccursString = "unbounded";
586 foreach (XmlTypeMapElementInfo einfo in infos)
588 if (einfo.IsTextElement) continue;
589 schoice.Items.Add (GetSchemaElement (currentSchema, einfo, true));
595 void ExportEnumSchema (XmlTypeMapping map)
597 if (IsMapExported (map)) return;
598 SetMapExported (map);
600 XmlSchema schema = GetSchema (map.XmlTypeNamespace);
601 XmlSchemaSimpleType stype = new XmlSchemaSimpleType ();
602 stype.Name = map.ElementName;
603 schema.Items.Add (stype);
605 XmlSchemaSimpleTypeRestriction rest = new XmlSchemaSimpleTypeRestriction ();
606 rest.BaseTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
607 EnumMap emap = (EnumMap) map.ObjectMap;
609 foreach (EnumMap.EnumMapMember emem in emap.Members)
611 XmlSchemaEnumerationFacet ef = new XmlSchemaEnumerationFacet ();
612 ef.Value = emem.XmlName;
613 rest.Facets.Add (ef);
615 stype.Content = rest;
618 XmlQualifiedName ExportArraySchema (XmlTypeMapping map, string defaultNamespace)
620 ListMap lmap = (ListMap) map.ObjectMap;
624 string name, ns, schemaNs;
625 lmap.GetArrayType (-1, out name, out ns);
626 if (ns == XmlSchema.Namespace) schemaNs = defaultNamespace;
629 if (IsMapExported (map)) return new XmlQualifiedName (lmap.GetSchemaArrayName (), schemaNs);
630 SetMapExported (map);
632 XmlSchema schema = GetSchema (schemaNs);
633 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
634 stype.Name = lmap.GetSchemaArrayName ();
635 schema.Items.Add (stype);
637 XmlSchemaComplexContent content = new XmlSchemaComplexContent();
638 content.IsMixed = false;
639 stype.ContentModel = content;
641 XmlSchemaComplexContentRestriction rest = new XmlSchemaComplexContentRestriction ();
642 content.Content = rest;
643 rest.BaseTypeName = new XmlQualifiedName ("Array", XmlSerializer.EncodingNamespace);
644 XmlSchemaAttribute at = new XmlSchemaAttribute ();
645 rest.Attributes.Add (at);
646 at.RefName = new XmlQualifiedName ("arrayType", XmlSerializer.EncodingNamespace);
648 XmlAttribute arrayType = Document.CreateAttribute ("arrayType", XmlSerializer.WsdlNamespace);
649 arrayType.Value = ns + (ns != "" ? ":" : "") + name;
650 at.UnhandledAttributes = new XmlAttribute [] { arrayType };
651 ImportNamespace (schema, XmlSerializer.WsdlNamespace);
653 XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) lmap.ItemInfo[0];
654 if (einfo.MappedType != null)
656 switch (einfo.TypeData.SchemaType)
658 case SchemaTypes.Enum:
659 ExportEnumSchema (einfo.MappedType);
661 case SchemaTypes.Array:
662 ExportArraySchema (einfo.MappedType, schemaNs);
664 case SchemaTypes.Class:
665 ExportClassSchema (einfo.MappedType);
670 return new XmlQualifiedName (lmap.GetSchemaArrayName (), schemaNs);
674 if (IsMapExported (map)) return new XmlQualifiedName (map.XmlType, map.XmlTypeNamespace);
676 SetMapExported (map);
677 XmlSchema schema = GetSchema (map.XmlTypeNamespace);
678 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
679 stype.Name = map.ElementName;
680 schema.Items.Add (stype);
682 XmlSchemaParticle spart = GetSchemaArrayElement (schema, lmap.ItemInfo);
683 if (spart is XmlSchemaChoice)
684 stype.Particle = spart;
687 XmlSchemaSequence seq = new XmlSchemaSequence ();
688 seq.Items.Add (spart);
689 stype.Particle = seq;
692 return new XmlQualifiedName (map.XmlType, map.XmlTypeNamespace);
700 if (xmlDoc == null) xmlDoc = new XmlDocument ();
705 bool IsMapExported (XmlTypeMapping map)
707 if (exportedMaps.ContainsKey (GetMapKey(map))) return true;
711 void SetMapExported (XmlTypeMapping map)
713 exportedMaps [GetMapKey(map)] = map;
716 bool IsElementExported (XmlTypeMapping map)
718 if (exportedElements.ContainsKey (GetMapKey(map))) return true;
719 if (map.TypeData.Type == typeof(object)) return true;
723 void SetElementExported (XmlTypeMapping map)
725 exportedElements [GetMapKey(map)] = map;
728 string GetMapKey (XmlTypeMapping map)
730 // Don't use type name for array types, since we can have different
731 // classes that represent the same array type (for example
732 // StringCollection and string[]).
734 if (map.TypeData.IsListType)
735 return GetArrayKeyName (map.TypeData) + " " + map.XmlType + " " + map.XmlTypeNamespace;
737 return map.TypeData.FullTypeName + " " + map.XmlType + " " + map.XmlTypeNamespace;
740 string GetArrayKeyName (TypeData td)
742 TypeData etd = td.ListItemTypeData;
743 return "*arrayof*" + (etd.IsListType ? GetArrayKeyName (etd) : etd.FullTypeName);
746 void CompileSchemas ()
748 // foreach (XmlSchema sc in schemas)
749 // sc.Compile (null);
752 XmlSchema GetSchema (string ns)
754 XmlSchema schema = schemas [ns];
757 schema = new XmlSchema ();
758 schema.TargetNamespace = ns;
760 schema.ElementFormDefault = XmlSchemaForm.Qualified;
761 schemas.Add (schema);
766 #endregion // Methods