void SetSchemaXmlSerializableType(XmlSerializableMapping map, XmlSchemaElement elem) { #if NET_2_0 if (map.SchemaType != null && map.Schema != null) { elem.SchemaType = map.SchemaType; return; } if (map.SchemaType == null && map.SchemaTypeName != null) { elem.SchemaTypeName = map.SchemaTypeName; elem.Name = map.SchemaTypeName.Name; return; } #endif XmlSchemaComplexType stype = new XmlSchemaComplexType(); XmlSchemaSequence seq = new XmlSchemaSequence(); if (map.Schema == null) { XmlSchemaElement selem = new XmlSchemaElement(); selem.RefName = new XmlQualifiedName("schema", XmlSchema.Namespace); seq.Items.Add(selem); seq.Items.Add(new XmlSchemaAny()); } else { XmlSchemaAny any = new XmlSchemaAny(); any.Namespace = map.Schema.TargetNamespace; seq.Items.Add(any); } stype.Particle = seq; elem.SchemaType = stype; }
void ExportXmlSerializableSchema(XmlSchema currentSchema, XmlSerializableMapping map) { if (IsMapExported(map)) { return; } SetMapExported(map); if (map.Schema == null) { return; } string targetNs = map.Schema.TargetNamespace; XmlSchema existingSchema = schemas [targetNs]; if (existingSchema == null) { schemas.Add(map.Schema); ImportNamespace(currentSchema, targetNs); } else if (existingSchema != map.Schema && !CanBeDuplicated(existingSchema, map.Schema)) { throw new InvalidOperationException("The namespace '" + targetNs + "' defined by the class '" + map.TypeFullName + "' is a duplicate."); } }
private void SetSchemaXmlSerializableType(XmlSerializableMapping map, XmlSchemaElement elem) { if (map.SchemaType != null && map.Schema != null) { elem.SchemaType = map.SchemaType; return; } if (map.SchemaType == null && map.SchemaTypeName != null) { elem.SchemaTypeName = map.SchemaTypeName; elem.Name = map.SchemaTypeName.Name; return; } XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(); XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); if (map.Schema == null) { XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.RefName = new XmlQualifiedName("schema", "http://www.w3.org/2001/XMLSchema"); xmlSchemaSequence.Items.Add(xmlSchemaElement); xmlSchemaSequence.Items.Add(new XmlSchemaAny()); } else { XmlSchemaAny xmlSchemaAny = new XmlSchemaAny(); xmlSchemaAny.Namespace = map.Schema.TargetNamespace; xmlSchemaSequence.Items.Add(xmlSchemaAny); } xmlSchemaComplexType.Particle = xmlSchemaSequence; elem.SchemaType = xmlSchemaComplexType; }
private void ExportXmlSerializableSchema(XmlSchema currentSchema, XmlSerializableMapping map) { if (this.IsMapExported(map)) { return; } this.SetMapExported(map); if (map.Schema == null) { return; } string targetNamespace = map.Schema.TargetNamespace; XmlSchema xmlSchema = this.schemas[targetNamespace]; if (xmlSchema == null) { this.schemas.Add(map.Schema); this.ImportNamespace(currentSchema, targetNamespace); } else if (xmlSchema != map.Schema && !XmlSchemaExporter.CanBeDuplicated(xmlSchema, map.Schema)) { throw new InvalidOperationException(string.Concat(new string[] { "The namespace '", targetNamespace, "' defined by the class '", map.TypeFullName, "' is a duplicate." })); } }
XmlTypeMapping CreateTypeMapping (TypeData typeData, XmlRootAttribute root, string defaultXmlType, string defaultNamespace) { string rootNamespace = defaultNamespace; string typeNamespace = null; string elementName; bool includeInSchema = true; XmlAttributes atts = null; bool nullable = CanBeNull (typeData); if (defaultXmlType == null) defaultXmlType = typeData.XmlType; if (!typeData.IsListType) { if (attributeOverrides != null) atts = attributeOverrides[typeData.Type]; if (atts != null && typeData.SchemaType == SchemaTypes.Primitive) throw new InvalidOperationException ("XmlRoot and XmlType attributes may not be specified for the type " + typeData.FullTypeName); } if (atts == null) atts = new XmlAttributes (typeData.Type); if (atts.XmlRoot != null && root == null) root = atts.XmlRoot; if (atts.XmlType != null) { if (atts.XmlType.Namespace != null) typeNamespace = atts.XmlType.Namespace; if (atts.XmlType.TypeName != null && atts.XmlType.TypeName != string.Empty) defaultXmlType = XmlConvert.EncodeLocalName (atts.XmlType.TypeName); includeInSchema = atts.XmlType.IncludeInSchema; } elementName = defaultXmlType; if (root != null) { if (root.ElementName.Length != 0) elementName = XmlConvert.EncodeLocalName(root.ElementName); if (root.Namespace != null) rootNamespace = root.Namespace; nullable = root.IsNullable; } if (rootNamespace == null) rootNamespace = ""; if (typeNamespace == null) typeNamespace = rootNamespace; XmlTypeMapping map; switch (typeData.SchemaType) { case SchemaTypes.XmlSerializable: map = new XmlSerializableMapping (root, elementName, rootNamespace, typeData, defaultXmlType, typeNamespace); break; case SchemaTypes.Primitive: if (!typeData.IsXsdType) map = new XmlTypeMapping (elementName, rootNamespace, typeData, defaultXmlType, XmlSerializer.WsdlTypesNamespace); else map = new XmlTypeMapping (elementName, rootNamespace, typeData, defaultXmlType, typeNamespace); break; default: map = new XmlTypeMapping (elementName, rootNamespace, typeData, defaultXmlType, typeNamespace); break; } map.IncludeInSchema = includeInSchema; map.IsNullable = nullable; relatedMaps.Add (map); return map; }
void SetSchemaXmlSerializableType (XmlSerializableMapping map, XmlSchemaElement elem) { if (map.SchemaType != null && map.Schema != null) { elem.SchemaType = map.SchemaType; return; } if (map.SchemaType == null && map.SchemaTypeName != null) { elem.SchemaTypeName = map.SchemaTypeName; elem.Name = map.SchemaTypeName.Name; return; } XmlSchemaComplexType stype = new XmlSchemaComplexType (); XmlSchemaSequence seq = new XmlSchemaSequence (); if (map.Schema == null) { XmlSchemaElement selem = new XmlSchemaElement (); selem.RefName = new XmlQualifiedName ("schema",XmlSchema.Namespace); seq.Items.Add (selem); seq.Items.Add (new XmlSchemaAny ()); } else { XmlSchemaAny any = new XmlSchemaAny (); any.Namespace = map.Schema.TargetNamespace; seq.Items.Add (any); } stype.Particle = seq; elem.SchemaType = stype; }
void ExportXmlSerializableSchema (XmlSchema currentSchema, XmlSerializableMapping map) { if (IsMapExported (map)) return; SetMapExported (map); if (map.Schema == null) return; string targetNs = map.Schema.TargetNamespace; XmlSchema existingSchema = schemas [targetNs]; if (existingSchema == null) { schemas.Add (map.Schema); ImportNamespace (currentSchema, targetNs); } else if (existingSchema != map.Schema && !CanBeDuplicated (existingSchema, map.Schema)) { throw new InvalidOperationException("The namespace '" + targetNs +"' defined by the class '" + map.TypeFullName + "' is a duplicate."); } }