e.Name = "bar";
s.Items.Add (e);
s.Compile (null);
+#if NET_2_0
+ schemaIntegerType = ((XmlSchemaSimpleType) a.AttributeSchemaType).Datatype;
+ schemaDecimalType = ((XmlSchemaSimpleType) b.AttributeSchemaType).Datatype;
+ schemaAnyType = e.ElementSchemaType as XmlSchemaComplexType;
+#else
schemaIntegerType = a.AttributeType as XmlSchemaDatatype;
schemaDecimalType = b.AttributeType as XmlSchemaDatatype;
schemaAnyType = e.ElementType as XmlSchemaComplexType;
+#endif
}
#region Fields
DataSet dataset;
+ bool forDataSet;
XmlSchema schema;
ArrayList relations = new ArrayList ();
// .ctor()
- public XmlSchemaDataImporter (DataSet dataset, XmlReader reader)
+ public XmlSchemaDataImporter (DataSet dataset, XmlReader reader, bool forDataSet)
{
this.dataset = dataset;
+ this.forDataSet = forDataSet;
dataset.DataSetName = "NewDataSet"; // Initialize always
schema = XmlSchema.Read (reader, null);
if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "schema" && reader.NamespaceURI == XmlSchema.Namespace)
if (datasetElement == null &&
IsDataSetElement (el))
datasetElement = el;
+#if NET_2_0
+ if (el.ElementSchemaType is XmlSchemaComplexType &&
+ el.ElementSchemaType != schemaAnyType)
+#else
if (el.ElementType is XmlSchemaComplexType &&
-el.ElementType != schemaAnyType)
+ el.ElementType != schemaAnyType)
+#endif
targetElements.Add (obj);
}
}
foreach (XmlSchemaObject obj in schema.Items) {
if (obj is XmlSchemaElement) {
XmlSchemaElement el = obj as XmlSchemaElement;
+#if NET_2_0
+ if (el.ElementSchemaType is XmlSchemaComplexType &&
+ el.ElementSchemaType != schemaAnyType)
+#else
if (el.ElementType is XmlSchemaComplexType &&
-el.ElementType != schemaAnyType)
+ el.ElementType != schemaAnyType)
+#endif
targetElements.Add (obj);
}
}
{
XmlSchemaElement el = p as XmlSchemaElement;
if (el != null) {
- XmlSchemaComplexType ct = el.ElementType as XmlSchemaComplexType;
+ XmlSchemaComplexType ct = null;
+#if NET_2_0
+ ct = el.ElementSchemaType as XmlSchemaComplexType;
+#else
+ ct = el.ElementType as XmlSchemaComplexType;
+#endif
if (ct == null || ct == schemaAnyType)
return true; // column element
if (ct.AttributeUses.Count > 0)
return;
// If type is not complex, just skip this element
+#if NET_2_0
+ if (! (el.ElementSchemaType is XmlSchemaComplexType && el.ElementSchemaType != schemaAnyType))
+#else
if (! (el.ElementType is XmlSchemaComplexType && el.ElementType != schemaAnyType))
+#endif
return;
if (IsDataSetElement (el)) {
ProcessDataSetElement (el);
return;
}
+ else
+ dataset.Locale = CultureInfo.CurrentCulture;
// Register as a top-level element
topLevelElements.Add (el);
dataset.DataSetName = el.Name;
this.datasetElement = el;
- // Search for msdata:Locale attribute
+ // Search for locale attributes
+ bool useCurrent = false;
if (el.UnhandledAttributes != null) {
foreach (XmlAttribute attr in el.UnhandledAttributes) {
+#if NET_2_0
+ if (attr.LocalName == "UseCurrentLocale" &&
+ attr.NamespaceURI == XmlConstants.MsdataNamespace)
+ useCurrent = true;
+#endif
if (attr.LocalName == "Locale" &&
attr.NamespaceURI == XmlConstants.MsdataNamespace) {
CultureInfo ci = new CultureInfo (attr.Value);
}
}
}
+#if NET_2_0
+ if (!useCurrent && !dataset.LocaleSpecified) // then set current culture instance _explicitly_
+ dataset.Locale = CultureInfo.CurrentCulture;
+#endif
// Process content type particle (and create DataTable)
- XmlSchemaComplexType ct = el.ElementType as XmlSchemaComplexType;
+ XmlSchemaComplexType ct = null;
+#if NET_2_0
+ ct = el.ElementSchemaType as XmlSchemaComplexType;
+#else
+ ct = el.ElementType as XmlSchemaComplexType;
+#endif
XmlSchemaParticle p = ct != null ? ct.ContentTypeParticle : null;
if (p != null)
HandleDataSetContentTypeParticle (p);
{
XmlSchemaElement el = p as XmlSchemaElement;
if (el != null) {
+#if NET_2_0
+ if (el.ElementSchemaType is XmlSchemaComplexType && el.RefName != el.QualifiedName)
+#else
if (el.ElementType is XmlSchemaComplexType && el.RefName != el.QualifiedName)
+#endif
ProcessDataTableElement (el);
}
else if (p is XmlSchemaGroupBase) {
DataTable table = new DataTable (tableName);
table.Namespace = el.QualifiedName.Namespace;
+ TableStructure oldTable = currentTable;
currentTable = new TableStructure (table);
dataset.Tables.Add (table);
// Handle complex type (NOTE: It is (or should be)
// impossible the type is other than complex type).
- XmlSchemaComplexType ct = (XmlSchemaComplexType) el.ElementType;
+ XmlSchemaComplexType ct = null;
+#if NET_2_0
+ ct = (XmlSchemaComplexType) el.ElementSchemaType;
+#else
+ ct = (XmlSchemaComplexType) el.ElementType;
+#endif
// Handle attributes
foreach (DictionaryEntry de in ct.AttributeUses)
table.Columns.Add ((DataColumn) de.Value);
foreach (DataColumn dc in currentTable.NonOrdinalColumns)
table.Columns.Add (dc);
+
+ currentTable = oldTable;
}
private DataRelation GenerateRelationship (RelationStructure rs)
DataColumn col = new DataColumn ();
col.ColumnName = attr.QualifiedName.Name;
col.Namespace = attr.QualifiedName.Namespace;
- XmlSchemaDatatype dt = GetSchemaPrimitiveType (attr.AttributeType);
+ XmlSchemaDatatype dt = null;
+#if NET_2_0
+ dt = GetSchemaPrimitiveType (((XmlSchemaSimpleType) attr.AttributeSchemaType).Datatype);
+#else
+ dt = GetSchemaPrimitiveType (attr.AttributeType);
+#endif
// This complicated check comes from the fact that
// MS.NET fails to map System.Object to anyType (that
// will cause ReadTypedObject() fail on XmlValidatingReader).
if (attr.Use == XmlSchemaUse.Required)
col.AllowDBNull = false;
+#if NET_2_0
+ FillFacet (col, attr.AttributeSchemaType as XmlSchemaSimpleType);
+#else
FillFacet (col, attr.AttributeType as XmlSchemaSimpleType);
+#endif
// Call this method after filling the name
ImportColumnMetaInfo (attr, attr.QualifiedName, col);
col.DefaultValue = GetElementDefaultValue (el);
col.AllowDBNull = (el.MinOccurs == 0);
+#if NET_2_0
+ if (el.ElementSchemaType is XmlSchemaComplexType && el.ElementSchemaType != schemaAnyType)
+#else
if (el.ElementType is XmlSchemaComplexType && el.ElementType != schemaAnyType)
+#endif
FillDataColumnComplexElement (parent, el, col);
else if (el.MaxOccurs != 1)
FillDataColumnRepeatedSimpleElement (parent, el, col);
// common process for element and attribute
private void ImportColumnMetaInfo (XmlSchemaAnnotated obj, XmlQualifiedName name, DataColumn col)
{
- int ordinal = -1;
if (obj.UnhandledAttributes != null) {
foreach (XmlAttribute attr in obj.UnhandledAttributes) {
if (attr.NamespaceURI != XmlConstants.MsdataNamespace)
col.ReadOnly = XmlConvert.ToBoolean (attr.Value);
break;
case XmlConstants.Ordinal:
- ordinal = int.Parse (attr.Value);
+ int ordinal = int.Parse (attr.Value);
break;
}
}
// If the element is not referenced one, the element will be handled later.
if (el.RefName == XmlQualifiedName.Empty)
- targetElements.Add (el);
+ ProcessDataTableElement (el);
}
cc2.Namespace = el.QualifiedName.Namespace;
cc2.ColumnMapping = MappingType.SimpleContent;
cc2.AllowDBNull = false;
+#if NET_2_0
+ cc2.DataType = ConvertDatatype (GetSchemaPrimitiveType (el.ElementSchemaType));
+#else
cc2.DataType = ConvertDatatype (GetSchemaPrimitiveType (el.ElementType));
+#endif
dt.Columns.Add (cc2);
dt.Columns.Add (cc);
col.ColumnName = XmlHelper.Decode (el.QualifiedName.Name);
col.Namespace = el.QualifiedName.Namespace;
col.ColumnMapping = MappingType.Element;
+#if NET_2_0
+ col.DataType = ConvertDatatype (GetSchemaPrimitiveType (el.ElementSchemaType));
+ FillFacet (col, el.ElementSchemaType as XmlSchemaSimpleType);
+#else
col.DataType = ConvertDatatype (GetSchemaPrimitiveType (el.ElementType));
FillFacet (col, el.ElementType as XmlSchemaSimpleType);
+#endif
ImportColumnMetaInfo (el, el.QualifiedName, col);
string tableName = c.TableName;
DataTable dt = dataset.Tables [tableName];
- if (dt == null)
- throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
+ if (dt == null) {
+ if (forDataSet)
+ throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
+ else
+ // nonexistent table name. .NET ignores it for DataTable.ReadXmlSchema().
+ return;
+ }
DataColumn [] cols = new DataColumn [c.Columns.Length];
for (int i = 0; i < cols.Length; i++) {
if (!c.IsConstraintOnly) {
// generate the relation.
- DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, false);
+ DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, true);
rel.Nested = c.IsNested;
rel.SetParentKeyConstraint (uniq);
rel.SetChildKeyConstraint (fkc);