2 // System.Data/DataSet.cs
5 // Christopher Podurgiel <cpodurgiel@msn.com>
6 // Daniel Morgan <danmorg@sc.rr.com>
7 // Rodrigo Moya <rodrigo@ximian.com>
8 // Stuart Caborn <stuart.caborn@virgin.net>
9 // Tim Coleman (tim@timcoleman.com)
10 // Ville Palo <vi64pa@koti.soon.fi>
12 // (C) Ximian, Inc. 2002
13 // Copyright (C) Tim Coleman, 2002
17 using System.Collections;
18 using System.ComponentModel;
19 using System.Globalization;
20 using System.Threading;
22 using System.Runtime.Serialization;
24 using System.Xml.Schema;
25 using System.Xml.Serialization;
27 namespace System.Data {
29 /// an in-memory cache of data
33 [DefaultProperty ("DataSetName")]
35 public class DataSet : MarshalByValueComponent, IListSource,
36 ISupportInitialize, ISerializable, IXmlSerializable {
37 private string dataSetName;
38 private string _namespace = "";
39 private string prefix;
40 private bool caseSensitive;
41 private bool enforceConstraints = true;
42 private DataTableCollection tableCollection;
43 private DataRelationCollection relationCollection;
44 private PropertyCollection properties;
45 private DataViewManager defaultView;
46 private CultureInfo locale = System.Threading.Thread.CurrentThread.CurrentCulture;
50 public DataSet() : this ("NewDataSet") {
53 public DataSet(string name) {
55 tableCollection = new DataTableCollection (this);
56 relationCollection = new DataRelationCollection.DataSetRelationCollection (this);
57 properties = new PropertyCollection();
61 protected DataSet(SerializationInfo info, StreamingContext context) : this () {
62 throw new NotImplementedException ();
65 #endregion // Constructors
67 #region Public Properties
69 [DataCategory ("Data")]
70 [DataSysDescription ("Indicates whether comparing strings within the DataSet is case sensitive.")]
71 [DefaultValue (false)]
72 public bool CaseSensitive {
73 get { return caseSensitive; }
75 foreach (DataTable T in Tables) {
76 if (T.VirginCaseSensitive)
77 T.CaseSensitive = value;
80 caseSensitive = value;
84 [DataCategory ("Data")]
85 [DataSysDescription ("The name of this DataSet.")]
87 public string DataSetName {
88 get { return dataSetName; }
89 set { dataSetName = value; }
92 [DataSysDescription ("Indicates a custom \"view\" of the data contained by the DataSet. This view allows filtering, searching, and navigating through the custom data view.")]
94 public DataViewManager DefaultViewManager {
96 if (defaultView == null)
97 defaultView = new DataViewManager (this);
102 [DataSysDescription ("Indicates whether constraint rules are to be followed.")]
103 [DefaultValue (true)]
104 public bool EnforceConstraints {
105 get { return enforceConstraints; }
106 set { enforceConstraints = value; }
110 [DataCategory ("Data")]
111 [DataSysDescription ("The collection that holds custom user information.")]
112 public PropertyCollection ExtendedProperties {
113 get { return properties; }
117 [DataSysDescription ("Indicates that the DataSet has errors.")]
118 public bool HasErrors {
121 throw new NotImplementedException ();
125 [DataCategory ("Data")]
126 [DataSysDescription ("Indicates a locale under which to compare strings within the DataSet.")]
127 public CultureInfo Locale {
132 if (locale == null || !locale.Equals(value)) {
133 // TODO: check if the new locale is valid
134 // TODO: update locale of all tables
140 public void Merge (DataRow[] rows)
142 Merge (rows, false, MissingSchemaAction.Add);
145 public void Merge (DataSet dataSet)
147 Merge (dataSet, false, MissingSchemaAction.Add);
150 public void Merge (DataTable table)
152 Merge (table, false, MissingSchemaAction.Add);
155 public void Merge (DataSet dataSet, bool preserveChanges)
157 Merge (dataSet, preserveChanges, MissingSchemaAction.Add);
161 public void Merge (DataRow[] rows, bool preserveChanges, MissingSchemaAction missingSchemaAction)
163 throw new NotImplementedException();
167 public void Merge (DataSet dataSet, bool preserveChanges, MissingSchemaAction missingSchemaAction)
169 throw new NotImplementedException();
173 public void Merge (DataTable table, bool preserveChanges, MissingSchemaAction missingSchemaAction)
175 throw new NotImplementedException();
178 [DataCategory ("Data")]
179 [DataSysDescription ("Indicates the XML uri namespace for the root element pointed at by this DataSet.")]
181 public string Namespace {
183 get { return _namespace; }
186 //TODO - trigger an event if this happens?
191 [DataCategory ("Data")]
192 [DataSysDescription ("Indicates the prefix of the namespace used for this DataSet.")]
194 public string Prefix {
196 get { return prefix; }
199 //TODO - trigger an event if this happens?
204 [DataCategory ("Data")]
205 [DataSysDescription ("The collection that holds the relations for this DatSet.")]
206 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
207 public DataRelationCollection Relations {
209 return relationCollection;
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
215 public override ISite Site {
218 throw new NotImplementedException ();
223 throw new NotImplementedException ();
227 [DataCategory ("Data")]
228 [DataSysDescription ("The collection that holds the tables for this DataSet.")]
229 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
230 public DataTableCollection Tables {
231 get { return tableCollection; }
234 #endregion // Public Properties
236 #region Public Methods
239 public void AcceptChanges()
241 foreach (DataTable tempTable in tableCollection)
242 tempTable.AcceptChanges ();
247 // TODO: if currently bound to a XmlDataDocument
248 // throw a NotSupportedException
249 for (int t = 0; t < tableCollection.Count; t++) {
250 tableCollection[t].Clear ();
254 public virtual DataSet Clone()
256 DataSet Copy = new DataSet ();
257 CopyProperties (Copy);
259 foreach (DataTable Table in Tables) {
260 Copy.Tables.Add (Table.Clone ());
266 // Copies both the structure and data for this DataSet.
267 public DataSet Copy()
269 DataSet Copy = new DataSet ();
270 CopyProperties (Copy);
272 // Copy DatSet's tables
273 foreach (DataTable Table in Tables) {
274 Copy.Tables.Add (Table.Copy ());
281 private void CopyProperties (DataSet Copy)
283 Copy.CaseSensitive = CaseSensitive;
284 //Copy.Container = Container
285 Copy.DataSetName = DataSetName;
286 //Copy.DefaultViewManager
288 Copy.EnforceConstraints = EnforceConstraints;
289 //Copy.ExtendedProperties
291 //Copy.Locale = Locale;
292 Copy.Namespace = Namespace;
293 Copy.Prefix = Prefix;
294 //Copy.Relations = Relations;
299 public DataSet GetChanges()
301 throw new NotImplementedException ();
305 public DataSet GetChanges(DataRowState rowStates)
307 throw new NotImplementedException ();
310 public string GetXml()
312 StringWriter Writer = new StringWriter ();
313 WriteXml (Writer, XmlWriteMode.IgnoreSchema);
314 return Writer.ToString ();
317 public string GetXmlSchema()
319 StringWriter Writer = new StringWriter ();
320 WriteXmlSchema (Writer);
321 return Writer.ToString ();
325 public bool HasChanges()
327 throw new NotImplementedException ();
331 public bool HasChanges(DataRowState rowState)
333 throw new NotImplementedException ();
337 public void InferXmlSchema(XmlReader reader, string[] nsArray)
341 public void InferXmlSchema(Stream stream, string[] nsArray)
343 InferXmlSchema (new XmlTextReader(stream), nsArray);
346 public void InferXmlSchema(TextReader reader, string[] nsArray)
348 InferXmlSchema (new XmlTextReader(reader), nsArray);
351 public void InferXmlSchema(string fileName, string[] nsArray)
353 XmlTextReader reader = new XmlTextReader(fileName);
355 InferXmlSchema (reader, nsArray);
361 public virtual void RejectChanges()
363 throw new NotImplementedException ();
366 public virtual void Reset()
368 throw new NotImplementedException ();
371 public void WriteXml(Stream stream)
373 XmlWriter writer = new XmlTextWriter(stream, null );
379 /// Writes the current data for the DataSet to the specified file.
381 /// <param name="filename">Fully qualified filename to write to</param>
382 public void WriteXml(string fileName)
384 XmlWriter writer = new XmlTextWriter(fileName, null );
391 public void WriteXml(TextWriter writer)
393 XmlWriter xwriter = new XmlTextWriter(writer );
398 public void WriteXml(XmlWriter writer)
400 WriteXml( writer, XmlWriteMode.IgnoreSchema );
403 public void WriteXml(Stream stream, XmlWriteMode mode)
405 XmlWriter writer = new XmlTextWriter(stream, null );
407 WriteXml( writer, mode );
410 public void WriteXml(string fileName, XmlWriteMode mode)
412 XmlWriter writer = new XmlTextWriter(fileName, null );
414 WriteXml( writer, mode );
419 public void WriteXml(TextWriter writer, XmlWriteMode mode)
421 XmlWriter xwriter = new XmlTextWriter(writer);
423 WriteXml( xwriter, mode );
426 public void WriteXml(XmlWriter writer, XmlWriteMode mode)
428 if (writer.WriteState == WriteState.Start)
429 writer.WriteStartDocument (true);
431 ((XmlTextWriter)writer).Formatting = Formatting.Indented;
432 WriteStartElement( writer, mode, Namespace, Prefix, DataSetName );
434 if( mode == XmlWriteMode.WriteSchema )
436 DoWriteXmlSchema( writer );
439 //Write out each table in order, providing it is not
440 //part of another table structure via a nested parent relationship
441 foreach( DataTable table in Tables )
443 bool isTopLevel = true;
444 foreach( DataRelation rel in table.ParentRelations )
455 WriteTable( writer, table, mode );
459 writer.WriteEndElement();
462 public void WriteXmlSchema(Stream stream)
464 XmlWriter writer = new XmlTextWriter(stream, null );
466 WriteXmlSchema( writer );
469 public void WriteXmlSchema(string fileName)
471 XmlWriter writer = new XmlTextWriter( fileName, null );
473 WriteXmlSchema( writer );
476 public void WriteXmlSchema(TextWriter writer)
478 XmlWriter xwriter = new XmlTextWriter( writer );
480 WriteXmlSchema( xwriter );
483 public void WriteXmlSchema(XmlWriter writer)
485 ((XmlTextWriter)writer).Formatting = Formatting.Indented;
486 //Create a skeleton doc and then write the schema
487 //proper which is common to the WriteXml method in schema mode
488 writer.WriteStartDocument();
490 DoWriteXmlSchema( writer );
492 writer.WriteEndDocument();
495 public void ReadXmlSchema(Stream stream)
497 XmlReader reader = new XmlTextReader( stream, null );
498 ReadXmlSchema( reader);
501 public void ReadXmlSchema(string str)
503 XmlReader reader = new XmlTextReader( str );
504 ReadXmlSchema( reader );
507 public void ReadXmlSchema(TextReader treader)
509 XmlReader reader = new XmlTextReader( treader );
510 ReadXmlSchema( reader );
513 public void ReadXmlSchema(XmlReader reader)
515 XmlSchemaMapper SchemaMapper = new XmlSchemaMapper (this);
516 SchemaMapper.Read (reader);
519 public XmlReadMode ReadXml (Stream stream)
521 return ReadXml (new XmlTextReader (stream));
524 public XmlReadMode ReadXml (string str)
526 return ReadXml (new XmlTextReader (str));
529 public XmlReadMode ReadXml (TextReader reader)
531 return ReadXml (new XmlTextReader (reader));
534 public XmlReadMode ReadXml (XmlReader r)
536 XmlDataLoader Loader = new XmlDataLoader (this);
537 // FIXME: somekinda exception?
539 return XmlReadMode.Auto; // FIXME
542 * If document is diffgram we will use diffgram
544 if (r.LocalName == "diffgram")
545 return ReadXml (r, XmlReadMode.DiffGram);
548 * If we already have a schema, or the document
549 * contains an in-line schema, sets XmlReadMode to ReadSchema.
552 // FIXME: is this always true: "if we have tables we have to have schema also"
553 if (Tables.Count > 0)
554 return ReadXml (r, XmlReadMode.ReadSchema);
557 * If we dont have a schema yet and document
558 * contains no inline-schema mode is XmlReadMode.InferSchema
561 return ReadXml (r, XmlReadMode.InferSchema);
565 public XmlReadMode ReadXml (Stream stream, XmlReadMode mode)
567 return ReadXml (new XmlTextReader (stream), mode);
570 public XmlReadMode ReadXml (string str, XmlReadMode mode)
572 return ReadXml (new XmlTextReader (str), mode);
575 public XmlReadMode ReadXml (TextReader reader, XmlReadMode mode)
577 return ReadXml (new XmlTextReader (reader), mode);
581 public XmlReadMode ReadXml (XmlReader reader, XmlReadMode mode)
583 XmlReadMode Result = XmlReadMode.Auto;
585 if (mode == XmlReadMode.DiffGram) {
586 XmlDiffLoader DiffLoader = new XmlDiffLoader (this);
587 DiffLoader.Load (reader);
588 Result = XmlReadMode.DiffGram;
591 XmlDataLoader Loader = new XmlDataLoader (this);
592 Result = Loader.LoadData (reader, mode);
598 #endregion // Public Methods
600 #region Public Events
602 [DataCategory ("Action")]
603 [DataSysDescription ("Occurs when it is not possible to merge schemas for two tables with the same name.")]
604 public event MergeFailedEventHandler MergeFailed;
606 #endregion // Public Events
614 #endregion Destructors
616 #region IListSource methods
617 IList IListSource.GetList ()
619 return DefaultViewManager;
622 bool IListSource.ContainsListCollection {
627 #endregion IListSource methods
629 #region ISupportInitialize methods
630 public void BeginInit ()
632 throw new NotImplementedException ();
635 public void EndInit ()
637 throw new NotImplementedException ();
641 #region ISerializable
642 void ISerializable.GetObjectData (SerializationInfo si, StreamingContext sc)
644 throw new NotImplementedException ();
648 #region Protected Methods
649 protected void GetSerializationData(SerializationInfo info, StreamingContext context)
651 string s = info.GetValue ("XmlDiffGram", typeof (String)) as String;
652 if (s != null) ReadXmlSerializable (new XmlTextReader(new StringReader(s)));
656 protected virtual System.Xml.Schema.XmlSchema GetSchemaSerializable()
658 return BuildSchema ();
661 protected virtual void ReadXmlSerializable(XmlReader reader)
663 ReadXml(reader, XmlReadMode.DiffGram); // FIXME
666 void IXmlSerializable.ReadXml(XmlReader reader)
668 reader.MoveToContent ();
669 reader.ReadStartElement (); // <DataSet>
671 reader.MoveToContent ();
672 ReadXmlSchema (reader);
674 reader.MoveToContent ();
675 ReadXml(reader, XmlReadMode.IgnoreSchema);
677 reader.MoveToContent ();
678 reader.ReadEndElement (); // </DataSet>
681 void IXmlSerializable.WriteXml(XmlWriter writer)
683 DoWriteXmlSchema (writer);
684 WriteXml(writer, XmlWriteMode.IgnoreSchema);
687 protected virtual bool ShouldSerializeRelations ()
692 protected virtual bool ShouldSerializeTables ()
698 protected internal virtual void OnPropertyChanging (PropertyChangedEventArgs pcevent)
703 protected virtual void OnRemoveRelation (DataRelation relation)
708 protected virtual void OnRemoveTable (DataTable table)
713 protected internal void RaisePropertyChanging (string name)
718 #region Private Xml Serialisation
720 private string WriteObjectXml( object o ) {
721 switch (Type.GetTypeCode (o.GetType ())) {
722 case TypeCode.Boolean:
723 return XmlConvert.ToString ((Boolean) o);
725 return XmlConvert.ToString ((Byte) o);
727 return XmlConvert.ToString ((Char) o);
728 case TypeCode.DateTime:
729 return XmlConvert.ToString ((DateTime) o);
730 case TypeCode.Decimal:
731 return XmlConvert.ToString ((Decimal) o);
732 case TypeCode.Double:
733 return XmlConvert.ToString ((Double) o);
735 return XmlConvert.ToString ((Int16) o);
737 return XmlConvert.ToString ((Int32) o);
739 return XmlConvert.ToString ((Int64) o);
741 return XmlConvert.ToString ((SByte) o);
742 case TypeCode.Single:
743 return XmlConvert.ToString ((Single) o);
744 case TypeCode.UInt16:
745 return XmlConvert.ToString ((UInt16) o);
746 case TypeCode.UInt32:
747 return XmlConvert.ToString ((UInt32) o);
748 case TypeCode.UInt64:
749 return XmlConvert.ToString ((UInt64) o);
751 if (o is TimeSpan) return XmlConvert.ToString ((TimeSpan) o);
752 if (o is Guid) return XmlConvert.ToString ((Guid) o);
756 private void WriteTable( XmlWriter writer, DataTable table, XmlWriteMode mode )
758 DataRow[] rows = new DataRow [table.Rows.Count];
759 table.Rows.CopyTo (rows, 0);
760 WriteTable (writer, rows, mode);
763 private void WriteTable( XmlWriter writer, DataRow[] rows, XmlWriteMode mode )
765 //The columns can be attributes, hidden, elements, or simple content
766 //There can be 0-1 simple content cols or 0-* elements
767 System.Collections.ArrayList atts;
768 System.Collections.ArrayList elements;
769 DataColumn simple = null;
771 if (rows.Length == 0) return;
772 DataTable table = rows[0].Table;
773 SplitColumns( table, out atts, out elements, out simple );
775 foreach( DataRow row in rows )
777 //sort out the namespacing
778 string nspc = table.Namespace.Length > 0 ? table.Namespace : Namespace;
780 // First check are all the rows null. If they are we just write empty element
781 bool AllNulls = true;
782 foreach (DataColumn dc in table.Columns) {
784 if (row [dc.ColumnName] != DBNull.Value) {
790 // If all of the columns were null, we have to write empty element
792 writer.WriteElementString (table.TableName, "");
796 WriteStartElement( writer, mode, nspc, table.Prefix, table.TableName );
798 foreach( DataColumn col in atts )
800 WriteAttributeString( writer, mode, col.Namespace, col.Prefix, col.ColumnName, row[col].ToString() );
805 writer.WriteString( WriteObjectXml(row[simple]) );
809 foreach( DataColumn col in elements )
811 string colnspc = nspc;
812 object rowObject = row [col];
814 if (rowObject == null || rowObject == DBNull.Value)
817 if( col.Namespace != null )
819 colnspc = col.Namespace;
822 //TODO check if I can get away with write element string
823 WriteStartElement( writer, mode, colnspc, col.Prefix, col.ColumnName );
824 writer.WriteString( WriteObjectXml(rowObject) );
825 writer.WriteEndElement();
829 foreach (DataRelation relation in table.ChildRelations) {
830 if (relation.Nested) {
831 WriteTable (writer, row.GetChildRows(relation), mode);
835 writer.WriteEndElement();
840 private void WriteStartElement( XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name )
844 case XmlWriteMode.WriteSchema:
845 if( nspc == null || nspc == "" )
847 writer.WriteStartElement( name );
849 else if( prefix != null )
851 writer.WriteStartElement(prefix, name, nspc );
855 writer.WriteStartElement( writer.LookupPrefix( nspc ), name, nspc );
858 case XmlWriteMode.DiffGram:
859 throw new NotImplementedException();
861 writer.WriteStartElement(name );
866 private void WriteAttributeString( XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name, string stringValue )
870 case XmlWriteMode.WriteSchema:
871 writer.WriteAttributeString(prefix, name, nspc );
873 case XmlWriteMode.DiffGram:
874 throw new NotImplementedException();
876 writer.WriteAttributeString(name, stringValue );
881 XmlSchema IXmlSerializable.GetSchema()
883 return BuildSchema ();
886 XmlSchema BuildSchema()
888 XmlSchema schema = new XmlSchema ();
889 schema.AttributeFormDefault = XmlSchemaForm.Qualified;
891 XmlSchemaElement elem = new XmlSchemaElement ();
892 elem.Name = DataSetName;
894 XmlDocument doc = new XmlDocument ();
896 XmlAttribute[] atts = new XmlAttribute [2];
897 atts[0] = doc.CreateAttribute (XmlConstants.MsdataPrefix, XmlConstants.IsDataSet, XmlConstants.MsdataNamespace);
898 atts[0].Value = "true";
900 atts[1] = doc.CreateAttribute (XmlConstants.MsdataPrefix, XmlConstants.Locale, XmlConstants.MsdataNamespace);
901 atts[1].Value = locale.Name;
902 elem.UnhandledAttributes = atts;
904 schema.Items.Add (elem);
906 XmlSchemaComplexType complex = new XmlSchemaComplexType ();
907 elem.SchemaType = complex;
909 XmlSchemaChoice choice = new XmlSchemaChoice ();
910 complex.Particle = choice;
911 choice.MaxOccursString = XmlConstants.Unbounded;
913 //Write out schema for each table in order, providing it is not
914 //part of another table structure via a nested parent relationship
915 foreach( DataTable table in Tables )
917 bool isTopLevel = true;
918 foreach( DataRelation rel in table.ParentRelations )
929 choice.Items.Add (GetTableSchema (doc, table));
933 //TODO - now add in the relationships as key and unique constraints etc
938 private XmlSchemaElement GetTableSchema (XmlDocument doc, DataTable table)
944 SplitColumns (table, out atts, out elements, out simple);
946 XmlSchemaElement elem = new XmlSchemaElement ();
947 elem.Name = table.TableName;
949 XmlSchemaComplexType complex = new XmlSchemaComplexType ();
950 elem.SchemaType = complex;
952 //TODO - what about the simple content?
953 if( elements.Count == 0 )
958 //A sequence of element types or a simple content node
960 XmlSchemaSequence seq = new XmlSchemaSequence ();
961 complex.Particle = seq;
963 foreach( DataColumn col in elements )
965 //<xs:element name=ColumnName type=MappedType Ordinal=index>
966 XmlSchemaElement colElem = new XmlSchemaElement ();
967 colElem.Name = col.ColumnName;
969 if (col.ColumnName != col.Caption && col.Caption != string.Empty)
971 XmlAttribute[] xatts = new XmlAttribute[1];
972 xatts[0] = doc.CreateAttribute (XmlConstants.MsdataPrefix, XmlConstants.Caption, XmlConstants.MsdataNamespace);
973 xatts[0].Value = col.Caption;
974 colElem.UnhandledAttributes = xatts;
977 if (col.DefaultValue.ToString () != string.Empty)
978 colElem.DefaultValue = col.DefaultValue.ToString ();
980 colElem.SchemaTypeName = MapType (col.DataType);
982 if( col.AllowDBNull )
984 colElem.MinOccurs = 0;
987 //writer.WriteAttributeString( XmlConstants.MsdataPrefix,
988 // XmlConstants.Ordinal,
989 // XmlConstants.MsdataNamespace,
990 // col.Ordinal.ToString() );
992 // Write SimpleType if column have MaxLength
993 if (col.MaxLength > -1)
\r
995 colElem.SchemaType = GetTableSimpleType (doc, col);
998 seq.Items.Add (colElem);
1002 //Then a list of attributes
1003 foreach( DataColumn col in atts )
1005 //<xs:attribute name=col.ColumnName form="unqualified" type=MappedType/>
1006 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1007 att.Name = col.ColumnName;
1008 att.Form = XmlSchemaForm.Unqualified;
1009 att.SchemaTypeName = MapType (col.DataType);
1010 complex.Attributes.Add (att);
1015 private XmlSchemaSimpleType GetTableSimpleType (XmlDocument doc, DataColumn col)
1018 XmlSchemaSimpleType simple = new XmlSchemaSimpleType ();
1021 XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction ();
1022 restriction.BaseTypeName = MapType (col.DataType);
1025 XmlSchemaMaxLengthFacet max = new XmlSchemaMaxLengthFacet ();
1026 max.Value = XmlConvert.ToString (col.MaxLength);
1027 restriction.Facets.Add (max);
1032 private void DoWriteXmlSchema( XmlWriter writer )
1034 GetSchemaSerializable ().Write (writer);
1038 /// Helper function to split columns into attributes elements and simple
1041 private void SplitColumns( DataTable table,
1043 out ArrayList elements,
1044 out DataColumn simple)
1046 //The columns can be attributes, hidden, elements, or simple content
1047 //There can be 0-1 simple content cols or 0-* elements
1048 atts = new System.Collections.ArrayList();
1049 elements = new System.Collections.ArrayList();
1052 //Sort out the columns
1053 foreach( DataColumn col in table.Columns )
1055 switch( col.ColumnMapping )
1057 case MappingType.Attribute:
1060 case MappingType.Element:
1061 elements.Add( col );
1063 case MappingType.SimpleContent:
1064 if( simple != null )
1066 throw new System.InvalidOperationException( "There may only be one simple content element" );
1071 //ignore Hidden elements
1077 private XmlQualifiedName MapType (Type type)
1079 switch (Type.GetTypeCode (type))
1081 case TypeCode.String: return XmlConstants.QnString;
1082 case TypeCode.Int16: return XmlConstants.QnShort;
1083 case TypeCode.Int32: return XmlConstants.QnInt;
1084 case TypeCode.Int64: return XmlConstants.QnLong;
1085 case TypeCode.Boolean: return XmlConstants.QnBoolean;
1086 case TypeCode.Byte: return XmlConstants.QnUnsignedByte;
1087 case TypeCode.Char: return XmlConstants.QnChar;
1088 case TypeCode.DateTime: return XmlConstants.QnDateTime;
1089 case TypeCode.Decimal: return XmlConstants.QnDecimal;
1090 case TypeCode.Double: return XmlConstants.QnDouble;
1091 case TypeCode.SByte: return XmlConstants.QnSbyte;
1092 case TypeCode.Single: return XmlConstants.QnFloat;
1093 case TypeCode.UInt16: return XmlConstants.QnUsignedShort;
1094 case TypeCode.UInt32: return XmlConstants.QnUnsignedInt;
1095 case TypeCode.UInt64: return XmlConstants.QnUnsignedLong;
1098 if (typeof (TimeSpan) == type) return XmlConstants.QnDuration;
1099 else if (typeof (System.Uri) == type) return XmlConstants.QnUri;
1100 else if (typeof (byte[]) == type) return XmlConstants.QnBase64Binary;
1101 else if (typeof (XmlQualifiedName) == type) return XmlConstants.QnXmlQualifiedName;
1102 else return XmlConstants.QnString;
1105 #endregion //Private Xml Serialisation