XML and relational data -- create a dataset ing from the XSD Architecture

Source: Internet
Author: User
How to Create a dataset ing from the XSD Architecture

This example illustrates how to create a dataset ing from the provided XML Schema Definition Language (XSD) architecture. In general, the architecture is metadata or data, but the XSD architecture also includes the relationship between data types. From an architecture, you can create a relational structure of tables and columns to store data that conforms to the provided architecture. This is the dataset relationship ing of the architecture.

 

VB datasetmapxsdschema. aspx

[Running example] | [View Source Code]

The dataset class is closely affiliated with the xmldatadocument class. The dataset class provides a view of the relationship between XML data loaded through xmldatadocument. To generate a ing between the two views, you must use the readxmlschema method of the dataset. You can use this method when creating xmldatadocument, as shown in the following xmldatadocument. dataset. readxmlschema call. Now, any changes made to the dataset are reflected in xmldatadocument, and vice versa.

To illustrate this relationship, the following sample code reads the books. XSD Schema file and loads it into the dataset attribute of xmldatadocument. Note that the readxmlschema method uses the schema loaded to streamreader to generate a link ing. If a link view has been defined in xmldatadocument, this example causes an exception.


StreamReader myStreamReader = null;            try            {            Console.WriteLine("Reading Schema file ...");            myStreamReader = new StreamReader(schema);            myXmlDataDocument.DataSet.ReadXmlSchema(myStreamReader);            }            catch (Exception e)            {            Console.WriteLine ("Exception: {0}", e.ToString());            }            finally            {            if (myStreamReader != null)            myStreamReader.Close();            }            
Dim myStreamReader as StreamReader = nothing            try            myStreamReader = new StreamReader(schema)            Console.WriteLine("Reading Schema file ...")            myXmlDataDocument.ReadXmlSchema(myStreamReader)            catch e as exception            Console.WriteLine ("Exception: " & e.ToString())            finally            If Not myStreamReader Is Nothing            myStreamReader.Close()            end if            end try            
C # VB  

So how do we know what the internal table generated from the architecture looks like? A dataset has a tables attribute, which is a set of internal tables. Each table has a column set, and each column has a column name (columnname) and a data type (datatype ). You only need to repeat these sets and set the output format to display the internal table structure generated from the provided architecture, as shown in the following code.

// Displays the DataSet tables structure            private void DisplayTableStructure()            {            Console.WriteLine("\r\nTable structure \r\n");            Console.WriteLine("Tables count=" + myXmlDataDocument.DataSet.Tables.Count.ToString());            for (int i = 0; i < myXmlDataDocument.DataSet.Tables.Count; i++)            {            Console.WriteLine("\tTableName='" + myXmlDataDocument.DataSet.Tables[i].TableName + "'.");            Console.WriteLine("\tColumns count=" + myXmlDataDocument.DataSet.Tables[i].Columns.Count.ToString());            for (int j = 0; j < myXmlDataDocument.DataSet.Tables[i].Columns.Count; j++)            {            Console.WriteLine("\t\tColumnName='" +            myXmlDataDocument.DataSet.Tables[i].Columns[j].ColumnName + "', type = "            + myXmlDataDocument.DataSet.Tables[i].Columns[j].DataType.ToString());            }            }            }            
' Displays the DataSet tables structure            private sub DisplayTableStructure()            Console.WriteLine()            Console.WriteLine("Table structure")            Console.WriteLine()            Console.WriteLine("Tables count=" & myXmlDataDocument.Tables.Count.ToString())            Dim i,j as integer            for i = 0 to (myXmlDataDocument.Tables.Count - 1)            Console.WriteLine("TableName='" & myXmlDataDocument.Tables(i).TableName & "'.")            Console.WriteLine("Columns count=" & myXmlDataDocument.Tables(i).Columns.Count.ToString())            for j = 0 to (myXmlDataDocument.Tables(i).Columns.Count - 1)            Console.WriteLine(Strings.chr(9) & "ColumnName='" & _            myXmlDataDocument.Tables(i).Columns(j).ColumnName & _"', type = " & _            myXmlDataDocument.Tables(i).Columns(j).DataType.ToString())            next            Console.WriteLine()            next            end sub            
C # VB  

The following output shows the table name, column name, and column type displayed by the displaytablestructure method in the books. XSD architecture.

Table structureTables count=3TableName='bookstore'.Columns count=1ColumnName='bookstore_Id', type = System.Int32TableName='book'.Columns count=5ColumnName='title', type = System.StringColumnName='price', type = System.DecimalColumnName='genre', type = System.StringColumnName='book_Id', type = System.Int32ColumnName='bookstore_Id', type = System.Int32TableName='author'.Columns count=3ColumnName='first-name', type = System.StringColumnName='last-name', type = System.StringColumnName='book_Id', type = System.Int32
Summary
  1. In general, the architecture is metadata or data, but the XSD architecture also includes the relationship between data types.
  2. From the XSD architecture, you can create a relational structure of tables and columns to store data that conforms to the provided architecture. This is the dataset ing.
  3. The readxmlschema method of the dataset generates internal mappings from the provided architecture.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.