示例#1
0
        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
            }
        }
示例#2
0
        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(); //Microsoft 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;
            }

        }
示例#3
0
        // Check for schema and skips or loads XSD schema if found. Returns true if schema found.
        // DataReader would be set on the first XML element after the schema of schema was found.
        // If no schema detected, reader's position will not change.
        private bool ProcessXsdSchema () {
            if (((object)dataReader.LocalName == XSD_SCHEMA && (object)dataReader.NamespaceURI == XSDNS )) {
                                                                    // Found XSD schema
                if ( ignoreSchema ) {                               // Should ignore it?
                    dataReader.Skip();                              // Yes, skip it
                }
                else {                                              // Have to load schema.
                    if ( isTableLevel ) {                           // Loading into the DataTable ?
                        dataTable.ReadXSDSchema(dataReader, false); // Invoke ReadXSDSchema on a table
                        nodeToSchemaMap = new XmlToDatasetMap(dataReader.NameTable, dataTable);
                    }                                               // Rebuild XML to DataSet map with new schema.
                    else {                                          // Loading into the DataSet ?
                        dataSet.ReadXSDSchema(dataReader, false);   // Invoke ReadXSDSchema on a DataSet
                        nodeToSchemaMap = new XmlToDatasetMap(dataReader.NameTable, dataSet);
                    }                                               // Rebuild XML to DataSet map with new schema.
                }
            }
            else if (((object)dataReader.LocalName == XDR_SCHEMA && (object)dataReader.NamespaceURI == XDRNS ) || 
                    ((object)dataReader.LocalName == SQL_SYNC   && (object)dataReader.NamespaceURI == UPDGNS))
            {
                dataReader.Skip();                                  // Skip XDR or SQL sync 
            }
            else {
                return false;                                       // No schema found. That means reader's position 
                                                                    // is unchganged. Report that to the caller.
            }

            return true;                                            // Schema found, reader's position changed.
        }
 internal void LoadData(XmlReader reader)
 {
     this.dataReader = DataTextReader.CreateReader(reader);
     int depth = this.dataReader.Depth;
     bool flag = this.isTableLevel ? this.dataTable.EnforceConstraints : this.dataSet.EnforceConstraints;
     this.InitNameTable();
     if (this.nodeToSchemaMap == null)
     {
         this.nodeToSchemaMap = this.isTableLevel ? new XmlToDatasetMap(this.dataReader.NameTable, this.dataTable) : new XmlToDatasetMap(this.dataReader.NameTable, this.dataSet);
     }
     if (this.isTableLevel)
     {
         this.dataTable.EnforceConstraints = false;
     }
     else
     {
         this.dataSet.EnforceConstraints = false;
         this.dataSet.fInReadXml = true;
     }
     if (this.topMostNode != null)
     {
         if (!this.isDiffgram && !this.isTableLevel)
         {
             DataTable schemaForNode = this.nodeToSchemaMap.GetSchemaForNode(this.topMostNode, this.FIgnoreNamespace(this.topMostNode)) as DataTable;
             if (schemaForNode != null)
             {
                 this.LoadTopMostTable(schemaForNode);
             }
         }
         this.topMostNode = null;
     }
     while (!this.dataReader.EOF)
     {
         if (this.dataReader.Depth < depth)
         {
             break;
         }
         if (reader.NodeType != XmlNodeType.Element)
         {
             this.dataReader.Read();
         }
         else
         {
             DataTable tableForNode = this.nodeToSchemaMap.GetTableForNode(this.dataReader, this.FIgnoreNamespace(this.dataReader));
             if (tableForNode == null)
             {
                 if (!this.ProcessXsdSchema())
                 {
                     this.dataReader.Read();
                 }
                 continue;
             }
             this.LoadTable(tableForNode, false);
         }
     }
     if (this.isTableLevel)
     {
         this.dataTable.EnforceConstraints = flag;
     }
     else
     {
         this.dataSet.fInReadXml = false;
         this.dataSet.EnforceConstraints = flag;
     }
 }
 internal void LoadData(XmlDocument xdoc)
 {
     if (xdoc.DocumentElement != null)
     {
         bool enforceConstraints;
         if (this.isTableLevel)
         {
             enforceConstraints = this.dataTable.EnforceConstraints;
             this.dataTable.EnforceConstraints = false;
         }
         else
         {
             enforceConstraints = this.dataSet.EnforceConstraints;
             this.dataSet.EnforceConstraints = false;
             this.dataSet.fInReadXml = true;
         }
         if (this.isTableLevel)
         {
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataTable, xdoc.NameTable);
         }
         else
         {
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataSet, xdoc.NameTable);
         }
         DataRow row = null;
         if (this.isTableLevel || ((this.dataSet != null) && this.dataSet.fTopLevelTable))
         {
             XmlElement documentElement = xdoc.DocumentElement;
             DataTable schemaForNode = (DataTable) this.nodeToSchemaMap.GetSchemaForNode(documentElement, this.FIgnoreNamespace(documentElement));
             if (schemaForNode != null)
             {
                 row = schemaForNode.CreateEmptyRow();
                 this.nodeToRowMap[documentElement] = row;
                 this.LoadRowData(row, documentElement);
                 schemaForNode.Rows.Add(row);
             }
         }
         this.LoadRows(row, xdoc.DocumentElement);
         this.AttachRows(row, xdoc.DocumentElement);
         if (this.isTableLevel)
         {
             this.dataTable.EnforceConstraints = enforceConstraints;
         }
         else
         {
             this.dataSet.fInReadXml = false;
             this.dataSet.EnforceConstraints = enforceConstraints;
         }
     }
 }
 private bool ProcessXsdSchema()
 {
     if ((this.dataReader.LocalName == this.XSD_SCHEMA) && (this.dataReader.NamespaceURI == this.XSDNS))
     {
         if (this.ignoreSchema)
         {
             this.dataReader.Skip();
         }
         else if (this.isTableLevel)
         {
             this.dataTable.ReadXSDSchema(this.dataReader, false);
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataReader.NameTable, this.dataTable);
         }
         else
         {
             this.dataSet.ReadXSDSchema(this.dataReader, false);
             this.nodeToSchemaMap = new XmlToDatasetMap(this.dataReader.NameTable, this.dataSet);
         }
     }
     else
     {
         if (((this.dataReader.LocalName != this.XDR_SCHEMA) || (this.dataReader.NamespaceURI != this.XDRNS)) && ((this.dataReader.LocalName != this.SQL_SYNC) || (this.dataReader.NamespaceURI != this.UPDGNS)))
         {
             return false;
         }
         this.dataReader.Skip();
     }
     return true;
 }