diff --git a/XmlSchemaClassGenerator.Tests/xsd/client/client.xsd b/XmlSchemaClassGenerator.Tests/xsd/client/client.xsd
index 2b6daab8..ed530d0b 100644
--- a/XmlSchemaClassGenerator.Tests/xsd/client/client.xsd
+++ b/XmlSchemaClassGenerator.Tests/xsd/client/client.xsd
@@ -65,7 +65,7 @@
-
+
diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs
index 284fb1ba..39c52bf5 100644
--- a/XmlSchemaClassGenerator/Generator.cs
+++ b/XmlSchemaClassGenerator/Generator.cs
@@ -337,6 +337,13 @@ private void BuildModel()
AttributeGroups = Set.Schemas().Cast().SelectMany(s => s.AttributeGroups.Values.Cast()).ToDictionary(g => g.QualifiedName);
Groups = Set.Schemas().Cast().SelectMany(s => s.Groups.Values.Cast()).ToDictionary(g => g.QualifiedName);
+ foreach (var globalType in Set.GlobalTypes.Values.Cast())
+ {
+ var schema = globalType.GetSchema();
+ var source = (schema == null ? null : new Uri(schema.SourceUri));
+ var type = CreateTypeModel(source, globalType, globalType.QualifiedName);
+ }
+
foreach (var rootElement in Set.GlobalElements.Values.Cast())
{
var source = new Uri(rootElement.GetSchema().SourceUri);
@@ -388,13 +395,6 @@ private void BuildModel()
type.RootElementName = rootElement.QualifiedName;
}
}
-
- foreach (var globalType in Set.GlobalTypes.Values.Cast())
- {
- var schema = globalType.GetSchema();
- var source = (schema == null ? null : new Uri(schema.SourceUri));
- var type = CreateTypeModel(source, globalType, globalType.QualifiedName);
- }
}
// see http://msdn.microsoft.com/en-us/library/z2w0sxhf.aspx
@@ -707,7 +707,7 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ
Type = CreateTypeModel(source, attribute.AttributeSchemaType, attributeQualifiedName),
IsAttribute = true,
IsNullable = attribute.Use != XmlSchemaUse.Required,
- DefaultValue = attribute.DefaultValue,
+ DefaultValue = attribute.DefaultValue ?? (attribute.Use != XmlSchemaUse.Optional ? attribute.FixedValue : null),
Form = attribute.Form == XmlSchemaForm.None ? attribute.GetSchema().AttributeFormDefault : attribute.Form,
XmlNamespace = attribute.QualifiedName.Namespace != "" && attribute.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? attribute.QualifiedName.Namespace : null,
};
@@ -779,7 +779,7 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM
IsNillable = element.IsNillable,
IsNullable = item.MinOccurs < 1.0m,
IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
- DefaultValue = element.DefaultValue,
+ DefaultValue = element.DefaultValue ?? (item.MinOccurs >= 1.0m ? element.FixedValue : null),
Form = element.Form == XmlSchemaForm.None ? element.GetSchema().ElementFormDefault : element.Form,
XmlNamespace = element.QualifiedName.Namespace != "" && element.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? element.QualifiedName.Namespace : null,
};