I have some code that creates a DOM from my schema:
XmlSchemaImporter importer = new XmlSchemaImporter(new XmlSchemas { schema });
CodeNamespace code = new CodeNamespace(targetNamespace);
XmlCodeExporter exporter = new XmlCodeExporter(code);
foreach (XmlSchemaElement element in schema.Elements.Values)
{
XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);
exporter.ExportTypeMapping(mapping);
}
As I want to create only types from my schema and not from imported schemas, I need to know the using-statements I need to create within my output-file. However the namespaces are not preserved within the DOM:
<import namespace="http://www.adv-online.de/namespaces/adv/gid/7.1" schemaLocation="Schema1.xsd"/>
<import namespace="http://www.liegenschaftsbestandsmodell.de/ns/bfm/1.2" schemaLocation="Schema2.xsd"/>
<element name="UP_Drossel" substitutionGroup="bfm:BP_TechnischeAnlage" type="abw:UP_DrosselType">
</element>
<complexType name="UP_DrosselType">
<complexContent>
<extension base="bfm:BP_TechnischeAnlageType">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="AblaufInKanten_UL_Rinne" type="adv:InverseReferenceType">
</element>
</sequence>
</extension>
</complexContent>
</complexType>
When I execute the code, the type of the reference is just InverseReference (not adv:InverseReference) without any indication about the namespace where this type is defined. So it is impossible to find that type and to add an appropriate using within my DOM:
var type = code.Types.Cast<CodeTypeDeclaration>().First(x => x.Name == "UP_DrosselType");
var field = type.Members.OfType<CodeMemberField>().First(x => x.Name == "AblaufInKanten_UL_Rinne");
var fieldType = field.Type.BaseType; // only returns InverseReference