/// <summary> /// Writes <see cref="PSMAttribute"/> as an XML element (with name, value and multiplicity) /// </summary> /// <param name="name">name of the attribute</param> /// <param name="attribute">written attribute</param> /// <param name="simpleTypeWriter">if a simpleType must be created for the attribute, it is written in this writer</param> public void AttributeAsElement(string name, PSMAttribute attribute, ref SimpleTypesWriter simpleTypeWriter) { Writer.WriteStartElement(NamespacePrefix, "element", "http://www.w3.org/2001/XMLSchema"); Writer.WriteAttributeString("name", name); TypeAttribute(attribute, ref simpleTypeWriter, true, false); Writer.WriteEndElement(); IsEmpty = false; AfterWriteDebug(); }
/// <summary> /// Writes <see cref="PSMAttribute"/> as an XML attribute (with name and value and default value) /// </summary> /// <param name="name">name of the attribute</param> /// <param name="attribute">written attribute</param> /// <param name="simpleTypeWriter">if a simpleType must be created for the attribute, it is written in this writer</param> /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and /// use="optional" is written.</param> public void Attribute(string name, PSMAttribute attribute, ref SimpleTypesWriter simpleTypeWriter, bool forceOptional) { if (attribute.Lower == 0 && attribute.Upper == 0) { return; } Writer.WriteStartElement(NamespacePrefix, "attribute", "http://www.w3.org/2001/XMLSchema"); Writer.WriteAttributeString("name", name); TypeAttribute(attribute, ref simpleTypeWriter, false, forceOptional); Writer.WriteEndElement(); IsEmpty = false; AfterWriteDebug(); }
/// <summary> /// Reset's the factory for new translation /// </summary> public void Initialize() { if (createdTreeDeclarations == null) { createdTreeDeclarations = new List <XmlSchemaWriter>(); } else { createdTreeDeclarations.Clear(); } _sbGlobalDeclarations = new StringBuilder(); globalDeclarations = CreateWriter(_sbGlobalDeclarations); _sbSimpleTypes = new StringBuilder(); XmlWriter writer = XmlWriter.Create(_sbSimpleTypes, writerSettings); simpleTypesDeclarations = new SimpleTypesWriter(writer, _sbSimpleTypes, Log); // ReSharper disable PossibleNullReferenceException writer.WriteStartElement("wrap"); // ReSharper restore PossibleNullReferenceException writer.WriteAttributeString("xmlns", "xs", null, "http://www.w3.org/2001/XMLSchema"); }
/// <summary> /// Writes type attribute /// </summary> /// <param name="property">property whose <see cref="Model.TypedElement.Type"/> attribute is being written</param> /// <param name="simpleTypeWriter">writer where simple type definition is written if the type was not /// yet used</param> /// <param name="useOccurs">if set to true, minOccurs and maxOccurs attributes are also written if /// <paramref name="property"/> multipicity is non-default</param> /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and /// use="optional" is written.</param> public void TypeAttribute(Property property, ref SimpleTypesWriter simpleTypeWriter, bool useOccurs, bool forceOptional) { DataType type = property.Type; if (type == null) { Writer.WriteAttributeString("type", "xs:string"); Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property)); } else { SimpleDataType simpleType = type as SimpleDataType; if (simpleType != null) { if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation)) { if (simpleType.Parent != null) { simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType); Writer.WriteAttributeString("type", simpleType.Name); } else { Writer.WriteAttributeString("type", NamespacePrefix + ":" + simpleType.DefaultXSDImplementation); } } else { if (type is SimpleDataType) { Writer.WriteAttributeString("type", NamespacePrefix + ":" + type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } else { Writer.WriteAttributeString("type", type.Name); Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type)); } } } else { Writer.WriteAttributeString("type", type.ToString()); } } if (!String.IsNullOrEmpty(property.Default)) { Writer.WriteAttributeString("default", property.Default); } if (forceOptional) { Writer.WriteAttributeString("use", "optional"); } else { if (!useOccurs) { if (property.Lower == 0 || property.Lower == null) { Writer.WriteAttributeString("use", "optional"); if (property.Upper > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } } else { if (property.Upper > 1 || property.Lower > 1) { Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString, property.Class, property)); } if (String.IsNullOrEmpty(property.Default)) { Writer.WriteAttributeString("use", "required"); } } } else { MultiplicityAttributes(property.Lower, property.Upper); } } IsEmpty = false; AfterWriteDebug(); }