System.Data.XmlDataLoader.LoadData C# (CSharp) Méthode

LoadData() private méthode

private LoadData ( XmlReader reader ) : void
reader System.Xml.XmlReader
Résultat void
        internal void LoadData(XmlReader reader)
        {
            _dataReader = DataTextReader.CreateReader(reader);

            int entryDepth = _dataReader.Depth;                  // Store current XML element depth so we'll read
                                                                 // correct portion of the XML and no more
            bool fEnforce = _isTableLevel ? _dataTable.EnforceConstraints : _dataSet.EnforceConstraints;
            // Keep constraints status for datataset/table
            InitNameTable();                                    // Adds DataSet namespaces to reader's nametable

            if (_nodeToSchemaMap == null)
            {                      // Create XML to dataset map
                _nodeToSchemaMap = _isTableLevel ? new XmlToDatasetMap(_dataReader.NameTable, _dataTable) :
                                                 new XmlToDatasetMap(_dataReader.NameTable, _dataSet);
            }

            if (_isTableLevel)
            {
                _dataTable.EnforceConstraints = false;           // Disable constraints
            }
            else
            {
                _dataSet.EnforceConstraints = false;             // Disable constraints
                _dataSet._fInReadXml = true;                      // We're in ReadXml now
            }

            if (_topMostNode != null)
            {                          // Do we have top node?
                if (!_isDiffgram && !_isTableLevel)
                {             // Not a diffgram  and not DataSet?
                    DataTable table = _nodeToSchemaMap.GetSchemaForNode(_topMostNode, FIgnoreNamespace(_topMostNode)) as DataTable;
                    // Try to match table in the dataset to this node
                    if (table != null)
                    {                        // Got the table ?
                        LoadTopMostTable(table);                // Load top most node
                    }
                }

                _topMostNode = null;                             // topMostNode is no more. Good riddance.
            }

            while (!_dataReader.EOF)
            {                          // Main XML parsing loop. Check for EOF just in case.
                if (_dataReader.Depth < entryDepth)              // Stop if we have consumed all elements allowed
                    break;

                if (reader.NodeType != XmlNodeType.Element)
                { // Read till Element is found
                    _dataReader.Read();
                    continue;
                }
                DataTable table = _nodeToSchemaMap.GetTableForNode(_dataReader, FIgnoreNamespace(_dataReader));
                // Try to get table for node
                if (table == null)
                {                            // Read till table is found
                    if (!ProcessXsdSchema())                    // Check for schemas...
                        _dataReader.Read();                      // Not found? Read next element.

                    continue;
                }

                LoadTable(table, false /* isNested */);        // Here goes -- load data for this table
                                                               // This is a root table, so it's not nested
            }

            if (_isTableLevel)
            {
                _dataTable.EnforceConstraints = fEnforce;        // Restore constraints and return
            }
            else
            {
                _dataSet._fInReadXml = false;                     // We're done.
                _dataSet.EnforceConstraints = fEnforce;          // Restore constraints and return
            }
        }

Same methods

XmlDataLoader::LoadData ( XmlDocument xdoc ) : void

Usage Example

        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