System.Data.XmlDataLoader.LoadData C# (CSharp) Метод

LoadData() приватный Метод

private LoadData ( XmlDocument xdoc ) : void
xdoc System.Xml.XmlDocument
Результат void
        internal void LoadData(XmlDocument xdoc)
        {
            if (xdoc.DocumentElement == null)
                return;

            bool saveEnforce;

            if (_isTableLevel)
            {
                saveEnforce = _dataTable.EnforceConstraints;
                _dataTable.EnforceConstraints = false;
            }
            else
            {
                saveEnforce = _dataSet.EnforceConstraints;
                _dataSet.EnforceConstraints = false;
                _dataSet._fInReadXml = true;
            }

            if (_isTableLevel)
            {
                _nodeToSchemaMap = new XmlToDatasetMap(_dataTable, xdoc.NameTable);
            }
            else
            {
                _nodeToSchemaMap = new XmlToDatasetMap(_dataSet, xdoc.NameTable);
            }
            /*
                        // Top level table or dataset ?
                        XmlElement rootElement = xdoc.DocumentElement;
                        Hashtable tableAtoms = new Hashtable();
                        XmlNode tabNode;
                        if (CountNonNSAttributes (rootElement) > 0)
                            dataSet.fTopLevelTable = true;
                        else {
                            for (tabNode = rootElement.FirstChild; tabNode != null; tabNode = tabNode.NextSibling) {
                                if (tabNode is XmlElement && tabNode.LocalName != Keywords.XSD_SCHEMA) {
                                    object value = tableAtoms[QualifiedName (tabNode.LocalName, tabNode.NamespaceURI)];
                                    if (value == null || (bool)value == false) {
                                        dataSet.fTopLevelTable = true;
                                        break;
                                    }
                                }
                            }
                        }
            */
            DataRow topRow = null;
            if (_isTableLevel || (_dataSet != null && _dataSet._fTopLevelTable))
            {
                XmlElement e = xdoc.DocumentElement;
                DataTable topTable = (DataTable)_nodeToSchemaMap.GetSchemaForNode(e, FIgnoreNamespace(e));
                if (topTable != null)
                {
                    topRow = topTable.CreateEmptyRow(); //enzol perf
                    _nodeToRowMap[e] = topRow;

                    // get all field values.
                    LoadRowData(topRow, e);
                    topTable.Rows.Add(topRow);
                }
            }

            LoadRows(topRow, xdoc.DocumentElement);
            AttachRows(topRow, xdoc.DocumentElement);


            if (_isTableLevel)
            {
                _dataTable.EnforceConstraints = saveEnforce;
            }
            else
            {
                _dataSet._fInReadXml = false;
                _dataSet.EnforceConstraints = saveEnforce;
            }
        }

Same methods

XmlDataLoader::LoadData ( XmlReader reader ) : void

Usage Example

Пример #1
0
        private void ReadXmlDiffgram(XmlReader reader) { // fill correctly
            int d = reader.Depth;
            bool fEnforce = this.EnforceConstraints;
            this.EnforceConstraints =false;
            DataTable newDt;
            bool isEmpty;

            if (this.Rows.Count == 0) {
                isEmpty = true;
                newDt = this;
            }
            else {
                isEmpty = false;
                newDt = this.Clone();
                newDt.EnforceConstraints = false;
            }

            newDt.Rows.nullInList = 0;

            reader.MoveToContent();

            if ((reader.LocalName != Keywords.DIFFGRAM) && (reader.NamespaceURI != Keywords.DFFNS))
                return;
            reader.Read();
            if (reader.NodeType == XmlNodeType.Whitespace) {
                MoveToElement(reader, reader.Depth - 1 /*iCurrentDepth*/); // skip over whitespaces.
            }

            newDt.fInLoadDiffgram = true;

            if (reader.Depth > d) {
                if ((reader.NamespaceURI != Keywords.DFFNS) && (reader.NamespaceURI != Keywords.MSDNS)) {
                    //we should be inside the dataset part
                    XmlDocument xdoc = new XmlDocument();
                    XmlElement node = xdoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    reader.Read();
                    if (reader.Depth-1 > d) {
                        XmlDataLoader xmlload = new XmlDataLoader(newDt, false, node, false);
                        xmlload.isDiffgram = true; // turn on the special processing
                        xmlload.LoadData(reader);
                    }
                    ReadEndElement(reader);
                }
                if (((reader.LocalName == Keywords.SQL_BEFORE) && (reader.NamespaceURI == Keywords.DFFNS)) ||
                    ((reader.LocalName == Keywords.MSD_ERRORS) && (reader.NamespaceURI == Keywords.DFFNS)))

                {
                    //this will consume the changes and the errors part
                    XMLDiffLoader diffLoader = new XMLDiffLoader();
                    diffLoader.LoadDiffGram(newDt, reader);
                }

                // get to the closing diff tag
                while(reader.Depth > d) {
                    reader.Read();
                }
                // read the closing tag
                ReadEndElement(reader);
            }

            if (newDt.Rows.nullInList > 0)
                throw ExceptionBuilder.RowInsertMissing(newDt.TableName);


            newDt.fInLoadDiffgram = false;
            List<DataTable> tableList = new List<DataTable>();
            tableList.Add(this);
            CreateTableList(this, tableList);

// this is terrible, optimize it
            for (int i = 0; i < tableList.Count ; i++) {
                DataRelation[] relations = tableList[i].NestedParentRelations;
                foreach(DataRelation rel in relations) {
                    if (rel != null && rel.ParentTable == tableList[i]) {
                        foreach (DataRow r in tableList[i].Rows) {
                            foreach (DataRelation rel2 in relations) {
                                r.CheckForLoops(rel2);
                            }
                        }
                    }
                }
            }

            if (!isEmpty) {
                this.Merge(newDt);
            }
            this.EnforceConstraints = fEnforce;
        }
All Usage Examples Of System.Data.XmlDataLoader::LoadData