System.Data.XmlDataTreeWriter.Save C# (CSharp) 메소드

Save() 개인적인 메소드

private Save ( XmlWriter xw, bool writeSchema ) : void
xw System.Xml.XmlWriter
writeSchema bool
리턴 void
        internal void Save(XmlWriter xw, bool writeSchema)
        {
            _xmlw = DataTextWriter.CreateWriter(xw);

            int countTopTable = _topLevelTables.Length;
            bool fWriteDSElement = true;

            string prefix = (_ds != null) ? ((_ds.Namespace.Length == 0) ? "" : _ds.Prefix) : ((_dt.Namespace.Length == 0) ? "" : _dt.Prefix);

            if (!writeSchema && _ds != null && _ds._fTopLevelTable && countTopTable == 1)
            {
                if (_ds.TopLevelTables()[0].Rows.Count == 1)
                    fWriteDSElement = false;
            }

            if (fWriteDSElement)
            {
                if (_ds == null)
                {
                    _xmlw.WriteStartElement(prefix, Keywords.DOCUMENTELEMENT, _dt.Namespace);
                }
                else
                {
                    if (_ds.DataSetName == null || _ds.DataSetName.Length == 0)
                        _xmlw.WriteStartElement(prefix, Keywords.DOCUMENTELEMENT, _ds.Namespace);
                    else
                        _xmlw.WriteStartElement(prefix, XmlConvert.EncodeLocalName(_ds.DataSetName), _ds.Namespace);
                }

                for (int i = 0; i < _dTables.Count; i++)
                {
                    if (((DataTable)_dTables[i])._xmlText != null)
                    {
                        _xmlw.WriteAttributeString(Keywords.XMLNS, Keywords.XSI, Keywords.XSD_XMLNS_NS, Keywords.XSINS);
                        break;
                    }
                }

                if (writeSchema)
                {
                    if (!_fFromTable)
                    {
                        new XmlTreeGen(SchemaFormat.Public).Save(_ds, _xmlw);
                    }
                    else
                    {
                        new XmlTreeGen(SchemaFormat.Public).Save(null, _dt, _xmlw, _writeHierarchy);
                    }
                }
            }

            for (int i = 0; i < _dTables.Count; i++)
            {
                foreach (DataRow row in ((DataTable)_dTables[i]).Rows)
                {
                    if (row.RowState == DataRowState.Deleted)
                        continue;
                    int parentRowCount = row.GetNestedParentCount();
                    if (parentRowCount == 0)
                    {
                        XmlDataRowWriter(row, ((DataTable)_dTables[i]).EncodedTableName);
                    }
                    else if (parentRowCount > 1)
                    {
                        DataTable dt = (DataTable)_dTables[i];
                        throw ExceptionBuilder.MultipleParentRows(dt.Namespace.Length == 0 ? dt.TableName : (dt.Namespace + dt.TableName));
                        // At all times a nested row can only have 0 or 1 parents, never more than 1
                    }
                }
            }

            if (fWriteDSElement)
                _xmlw.WriteEndElement();
            _xmlw.Flush();
        }

Usage Example

예제 #1
0
        public void WriteXml(XmlWriter writer, XmlWriteMode mode, bool writeHierarchy)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.WriteXml|API> %d#, mode=%d{ds.XmlWriteMode}\n", ObjectID,  (int)mode);
            try{
                if (this.tableName.Length == 0) {
                    throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName();
                }
                // Generate SchemaTree and write it out
                if (writer != null) {

                    if (mode == XmlWriteMode.DiffGram) { // FIX THIS
                        // Create and save the updates
                        new NewDiffgramGen(this, writeHierarchy).Save(writer, this);
                    }
                    else {
                        // Create and save xml data
                        if (mode == XmlWriteMode.WriteSchema) {
                            DataSet ds = null;
                            string tablenamespace = this.tableNamespace;
                            if (null == this.DataSet) {
                                ds = new DataSet();
                                // if user set values on DataTable, it isn't necessary
                                // to set them on the DataSet because they won't be inherited
                                // but it is simpler to set them in both places

                                // if user did not set values on DataTable, it is required
                                // to set them on the DataSet so the table will inherit
                                // the value already on the Datatable
                                ds.SetLocaleValue(_culture, _cultureUserSet);
                                ds.CaseSensitive = this.CaseSensitive;
                                ds.Namespace = this.Namespace;
                                ds.RemotingFormat = this.RemotingFormat;
                                ds.Tables.Add(this);
                            }

                            if (writer != null) {
                                XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy);
                                xmldataWriter.Save(writer, /*mode == XmlWriteMode.WriteSchema*/true);
                            }
                            if (null != ds) {
                                ds.Tables.Remove(this);
                                this.tableNamespace = tablenamespace;
                            }
                        }
                        else {
                            XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy);
                            xmldataWriter.Save(writer,/*mode == XmlWriteMode.WriteSchema*/ false);
                        }
                    }
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
All Usage Examples Of System.Data.XmlDataTreeWriter::Save