2. Create second xsd file wich has elements which uses types from first file
3. Generate code for second file
Result: Types from first xsd file generated in code for second file.
This issue requires http://www.codeplex.com/Xsd2Code/WorkItem/View.aspx?WorkItemId=6941 to be fixed.
Comments: ** Comment from web user: atamas **
As I understand it works only when the included types have different target namespace, because of this check in Codextension.cs/ContainsTypeName method:
//fallback: Check if the namespace attribute of the type equals the namespace of the file.
//first, find the XmlType attribute.
foreach (CodeAttributeDeclaration attribute in type.CustomAttributes)
{
if (attribute.Name == "System.Xml.Serialization.XmlTypeAttribute")
{
foreach (CodeAttributeArgument argument in attribute.Arguments)
{
if (argument.Name == "Namespace")
{
if (((CodePrimitiveExpression)argument.Value).Value == schema.TargetNamespace)
{
return true;
}
}
}
}
}
It returns true if the type has the same target namespace (even if it's in a different file), so the Process method won't exclude the type.
And because xs:include will always enforce the same target namespace, it will never work for that.
From http://www.w3schools.com/schema/el_include.asp :
"With included schemas, the included files must all reference the same target namespace. If the schema target namespace don't match, the include won't work"
I think that's why it works for imports (sometimes) and not for includes. For imports it also works only if the imported file has different target namespace.
I commented out this part of the code, and it works fine for me. I don't know when would I need that check (I suppose it was there for reason).