System.Data.DataSet.ReadXmlSchema C# (CSharp) Method

ReadXmlSchema() private method

private ReadXmlSchema ( XmlReader reader, bool denyResolving ) : void
reader XmlReader
denyResolving bool
return void
        internal void ReadXmlSchema(XmlReader reader, bool denyResolving)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.ReadXmlSchema|INFO> {0}, reader, denyResolving={1}", ObjectID, denyResolving);
            try
            {
                int iCurrentDepth = -1;

                if (reader == null)
                {
                    return;
                }

                if (reader is XmlTextReader)
                {
                    ((XmlTextReader)reader).WhitespaceHandling = WhitespaceHandling.None;
                }

                XmlDocument xdoc = new XmlDocument(); // we may need this to infer the schema

                if (reader.NodeType == XmlNodeType.Element)
                {
                    iCurrentDepth = reader.Depth;
                }

                reader.MoveToContent();

                if (reader.NodeType == XmlNodeType.Element)
                {
                    // if reader points to the schema load it...
                    if (reader.LocalName == Keywords.XDR_SCHEMA && reader.NamespaceURI == Keywords.XDRNS)
                    {
                        // load XDR schema and exit
                        ReadXDRSchema(reader);
                        return;
                    }

                    if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI == Keywords.XSDNS)
                    {
                        // load XSD schema and exit
                        ReadXSDSchema(reader, denyResolving);
                        return;
                    }

                    if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI.StartsWith(Keywords.XSD_NS_START, StringComparison.Ordinal))
                    {
                        throw ExceptionBuilder.DataSetUnsupportedSchema(Keywords.XSDNS);
                    }

                    // ... otherwise backup the top node and all its attributes
                    XmlElement topNode = xdoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    if (reader.HasAttributes)
                    {
                        int attrCount = reader.AttributeCount;
                        for (int i = 0; i < attrCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            if (reader.NamespaceURI.Equals(Keywords.XSD_XMLNS_NS))
                            {
                                topNode.SetAttribute(reader.Name, reader.GetAttribute(i));
                            }
                            else
                            {
                                XmlAttribute attr = topNode.SetAttributeNode(reader.LocalName, reader.NamespaceURI);
                                attr.Prefix = reader.Prefix;
                                attr.Value = reader.GetAttribute(i);
                            }
                        }
                    }
                    reader.Read();

                    while (MoveToElement(reader, iCurrentDepth))
                    {
                        // if reader points to the schema load it...
                        if (reader.LocalName == Keywords.XDR_SCHEMA && reader.NamespaceURI == Keywords.XDRNS)
                        {
                            // load XDR schema and exit
                            ReadXDRSchema(reader);
                            return;
                        }

                        if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI == Keywords.XSDNS)
                        {
                            // load XSD schema and exit
                            ReadXSDSchema(reader, denyResolving);
                            return;
                        }

                        if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI.StartsWith(Keywords.XSD_NS_START, StringComparison.Ordinal))
                        {
                            throw ExceptionBuilder.DataSetUnsupportedSchema(Keywords.XSDNS);
                        }

                        XmlNode node = xdoc.ReadNode(reader);
                        topNode.AppendChild(node);
                    }

                    // read the closing tag of the current element
                    ReadEndElement(reader);

                    // if we are here no schema has been found
                    xdoc.AppendChild(topNode);

                    // so we InferSchema
                    InferSchema(xdoc, null, XmlReadMode.Auto);
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Same methods

DataSet::ReadXmlSchema ( Stream stream ) : void
DataSet::ReadXmlSchema ( TextReader reader ) : void
DataSet::ReadXmlSchema ( XmlReader reader ) : void
DataSet::ReadXmlSchema ( string fileName ) : void

Usage Example

 protected DatasetPatrols(SerializationInfo info, StreamingContext context) {
     string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
     if ((strSchema != null)) {
         DataSet ds = new DataSet();
         ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));
         if ((ds.Tables["Patrols"] != null)) {
             this.Tables.Add(new PatrolsDataTable(ds.Tables["Patrols"]));
         }
         this.DataSetName = ds.DataSetName;
         this.Prefix = ds.Prefix;
         this.Namespace = ds.Namespace;
         this.Locale = ds.Locale;
         this.CaseSensitive = ds.CaseSensitive;
         this.EnforceConstraints = ds.EnforceConstraints;
         this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
         this.InitVars();
     }
     else {
         this.InitClass();
     }
     this.GetSerializationData(info, context);
     System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
     this.Tables.CollectionChanged += schemaChangedHandler;
     this.Relations.CollectionChanged += schemaChangedHandler;
 }
All Usage Examples Of System.Data.DataSet::ReadXmlSchema