internal void HandleColumnType(DataColumn col, XmlDocument dc, XmlElement root, XmlElement schema)
{
string keyword = Keywords.TYPE;
if (col.ColumnMapping == MappingType.SimpleContent)
keyword = Keywords.BASE;
if (col.SimpleType != null)
{
// generate simpleType node
SimpleType stNode = col.SimpleType;
while (stNode != null)
{
// for remoting, set the msdata:targetNamespace for the simpleType.
XmlNode type;
string name = stNode.Name;
if (name != null && name.Length != 0)
{
// For remoting, always need to work with root schema's namespace
string nSpace = (_schFormat != SchemaFormat.Remoting) ? stNode.Namespace :
(col.Table.DataSet != null ? col.Table.DataSet.Namespace : col.Table.Namespace);
// for remoting we need to use columns NS, for other cases it is wrong to get Columns NS, we need to take type's namespace
XmlElement schNode = GetSchema(nSpace);
//SchNode To Ensure BaseSimpleType Prefix is Generated
if (stNode.BaseSimpleType != null && stNode.BaseSimpleType.Namespace != null && stNode.BaseSimpleType.Namespace.Length > 0)
GetSchema(stNode.BaseSimpleType.Namespace); //it will ensure a prefix has been created for this namespace
type = stNode.ToNode(dc, _prefixes, (_schFormat == SchemaFormat.Remoting));
if (stNode == col.SimpleType)
{
string prefix = (string)_prefixes[nSpace];
// set the columns's type
if (prefix != null && prefix.Length > 0)
{
if (_schFormat != SchemaFormat.Remoting)
root.SetAttribute(keyword, (prefix + ":" + name)); // look at below,this loop assumes we would be here just oen time: Its Wrong
else // As all types (in remoting) belong to the same namespace, just write type name
root.SetAttribute(keyword, name);
}
else
root.SetAttribute(keyword, name);
// set the root to the actual type, do not overwrite it in the iteration.
}
XmlElement elmSimpeType = FindSimpleType(schNode, name);
if (elmSimpeType == null)
{
// if we don't have the defenition for this simpleType yet. Add it
schNode.AppendChild(type);
}
else
{
#if DEBUG
// enzol: TO DO: replace the constructor with IsEqual(XmlElement)
// Debug.Assert(col.SimpleType.IsEqual(new SimpleType(elmSimpeType)), "simpleTypes with the same name have to be the same: "+name);
#endif
}
}
else
{
//SchNode To Ensure BaseSimpleType Prefix is Generated
if (stNode.BaseSimpleType != null && stNode.BaseSimpleType.Namespace != null && stNode.BaseSimpleType.Namespace.Length > 0)
GetSchema(stNode.BaseSimpleType.Namespace); //it will ensure a prefix has been created for this namespace
type = stNode.ToNode(dc, _prefixes, _schFormat == SchemaFormat.Remoting);
root.AppendChild(type);
}
stNode = stNode.BaseSimpleType;
}
}
else if (col.XmlDataType != null && col.XmlDataType.Length != 0 && XSDSchema.IsXsdType(col.XmlDataType))
{
root.SetAttribute(keyword, XSDSchema.QualifiedName(col.XmlDataType));
}
else
{
string typeName = XmlDataTypeName(col.DataType); // do not update the hashtable, as it will not write msdata:DataType
if (typeName == null || typeName.Length == 0)
{
if (col.DataType == typeof(Guid) || col.DataType == typeof(Type))
{
typeName = "string";
}
else
{
if (col.ColumnMapping == MappingType.Attribute)
{
XmlTreeGen.ValidateColumnMapping(col.DataType);
}
typeName = Keywords.XSD_ANYTYPE;
}
}
root.SetAttribute(keyword, XSDSchema.QualifiedName(typeName));
}
}