internal void Save(XmlWriter xmlw, DataTable table) { this._xmlw = DataTextWriter.CreateWriter(xmlw); this._xmlw.WriteStartElement("diffgr", "diffgram", "urn:schemas-microsoft-com:xml-diffgram-v1"); this._xmlw.WriteAttributeString("xmlns", "msdata", null, "urn:schemas-microsoft-com:xml-msdata"); if (!this.EmptyData()) { if (table != null) { new XmlDataTreeWriter(table, this._writeHierarchy).SaveDiffgramData(this._xmlw, this.rowsOrder); } else { new XmlDataTreeWriter(this._ds).SaveDiffgramData(this._xmlw, this.rowsOrder); } if (table == null) { for (int i = 0; i < this._ds.Tables.Count; i++) { this.GenerateTable(this._ds.Tables[i]); } } else { for (int j = 0; j < this._tables.Count; j++) { this.GenerateTable((DataTable)this._tables[j]); } } if (this.fBefore) { this._xmlw.WriteEndElement(); } if (table == null) { for (int k = 0; k < this._ds.Tables.Count; k++) { this.GenerateTableErrors(this._ds.Tables[k]); } } else { for (int m = 0; m < this._tables.Count; m++) { this.GenerateTableErrors((DataTable)this._tables[m]); } } if (this.fErrors) { this._xmlw.WriteEndElement(); } } this._xmlw.WriteEndElement(); this._xmlw.Flush(); }
internal void SaveDiffgramData(XmlWriter xw, Hashtable rowsOrder) { this._xmlw = DataTextWriter.CreateWriter(xw); this.isDiffgram = true; this.rowsOrder = rowsOrder; string prefix = (this._ds != null) ? ((this._ds.Namespace.Length == 0) ? "" : this._ds.Prefix) : ((this._dt.Namespace.Length == 0) ? "" : this._dt.Prefix); if (((this._ds == null) || (this._ds.DataSetName == null)) || (this._ds.DataSetName.Length == 0)) { this._xmlw.WriteStartElement(prefix, "DocumentElement", (this._dt.Namespace == null) ? "" : this._dt.Namespace); } else { this._xmlw.WriteStartElement(prefix, XmlConvert.EncodeLocalName(this._ds.DataSetName), this._ds.Namespace); } for (int i = 0; i < this._dTables.Count; i++) { DataTable table = (DataTable)this._dTables[i]; foreach (DataRow row in table.Rows) { if (row.RowState != DataRowState.Deleted) { int nestedParentCount = row.GetNestedParentCount(); if (nestedParentCount == 0) { DataTable table2 = (DataTable)this._dTables[i]; this.XmlDataRowWriter(row, table2.EncodedTableName); } else if (nestedParentCount > 1) { throw ExceptionBuilder.MultipleParentRows((table.Namespace.Length == 0) ? table.TableName : (table.Namespace + table.TableName)); } } } } this._xmlw.WriteEndElement(); this._xmlw.Flush(); }
internal void Save(XmlWriter xw, bool writeSchema) { this._xmlw = DataTextWriter.CreateWriter(xw); int length = this.topLevelTables.Length; bool flag = true; string prefix = (this._ds != null) ? ((this._ds.Namespace.Length == 0) ? "" : this._ds.Prefix) : ((this._dt.Namespace.Length == 0) ? "" : this._dt.Prefix); if (((!writeSchema && (this._ds != null)) && (this._ds.fTopLevelTable && (length == 1))) && (this._ds.TopLevelTables()[0].Rows.Count == 1)) { flag = false; } if (flag) { if (this._ds == null) { this._xmlw.WriteStartElement(prefix, "DocumentElement", this._dt.Namespace); } else if ((this._ds.DataSetName == null) || (this._ds.DataSetName.Length == 0)) { this._xmlw.WriteStartElement(prefix, "DocumentElement", this._ds.Namespace); } else { this._xmlw.WriteStartElement(prefix, XmlConvert.EncodeLocalName(this._ds.DataSetName), this._ds.Namespace); } for (int j = 0; j < this._dTables.Count; j++) { if (((DataTable)this._dTables[j]).xmlText != null) { this._xmlw.WriteAttributeString("xmlns", "xsi", "http://www.w3.org/2000/xmlns/", "http://www.w3.org/2001/XMLSchema-instance"); break; } } if (writeSchema) { if (!this.fFromTable) { new XmlTreeGen(SchemaFormat.Public).Save(this._ds, this._xmlw); } else { new XmlTreeGen(SchemaFormat.Public).Save(null, this._dt, this._xmlw, this._writeHierarchy); } } } for (int i = 0; i < this._dTables.Count; i++) { foreach (DataRow row in ((DataTable)this._dTables[i]).Rows) { if (row.RowState != DataRowState.Deleted) { int nestedParentCount = row.GetNestedParentCount(); if (nestedParentCount == 0) { this.XmlDataRowWriter(row, ((DataTable)this._dTables[i]).EncodedTableName); } else if (nestedParentCount > 1) { DataTable table = (DataTable)this._dTables[i]; throw ExceptionBuilder.MultipleParentRows((table.Namespace.Length == 0) ? table.TableName : (table.Namespace + table.TableName)); } } } } if (flag) { this._xmlw.WriteEndElement(); } this._xmlw.Flush(); }