Export (0) Print
Expand All

Creating Tables in XML Schemas

Visual Studio .NET 2003

You can create tables and columns in XML Schemas in order to validate that table representations in XML data contain valid structure as well as valid data types. For more information about tables and columns, see Tables, Columns, Keys, and Constraints in XML Schemas.

Visual representation of a table in the XML Designer

1fw5e4t0.vbcustomerstable(en-us,VS.71).gif

In XML Schemas, tables can be constructed manually or automatically with the XML Designer depending on the availability of a data source that represents the tables you need to validate within your application. You can also construct your schema both ways. For example: suppose you need to create a schema to validate XML data that includes a table with customer information and a table with customer feedback from your customer service department. Your organization already has the customer information table in an existing database; this can be created in your new schema automatically from your existing data source. The new table with customer feedback can be created manually and a relationship can be defined between the two tables.

Automatic Table Construction

You can use individual tables that are in existing data sources to easily construct schemas and datasets.

To automatically create table representations in XML Schemas using existing data sources.

  1. In Solution Explorer, right click the project you want to add the dataset to, select Add, and then select Add New Item.
  2. In the Add New Item dialog box, select Dataset, give the dataset a name, and then click Open.

    Visual Studio adds a new, blank schema file (.xsd) to the project as well as a corresponding DataSet class file.

    Note   The name you use will also be the name of the DataSet class file generated from the schema.
  3. In Server Explorer, expand the Data Connections node and then expand the node for the connection to the data source you want to use.
    Note   If you don't already have a connection, create one. For more information, see Adding New Data Connections in Server Explorer.
  4. In the Connection node, expand the node for the Tables you want to infer the schema structure from.
  5. Drag the selected table onto the XML Designer.
  6. Save the schema.

    Visual Studio creates the schema structure from the elements you specify and regenerates the corresponding class file for your typed dataset.

  7. Repeat steps 4 and 5 to add more tables to your schema.

Manual Table Construction

If your schema requires table representations that have no available data sources to base them on, you can construct them manually with the XML Designer.

To manually create table representations in XML Schemas

  1. In Solution Explorer, right-click the project you want to add the dataset to, select Add, and then select Add New Item.
  2. In the Add New Item dialog box, select Dataset, give the dataset a name, and then click Open.

    Visual Studio adds a new, blank schema file (.xsd) to the project as well as a corresponding DataSet class file.

    Note   The name you use will also be the name of the DataSet class file generated from the schema.
  3. Drag an Element from the XML Schema tab of the Toolbox onto the designer.

    A table definition is added to the schema,

  4. Name the table by overwriting Element1 in grid header of the element.
  5. Move to a blank line in the table definition and select either Element or Attribute from the type drop-down. For more information, see Tables, Columns, Keys, and Constraints in XML Schemas.

    A column definition is added to the schema.

  6. Assign a name and a data type to the new column definition.
  7. Repeat Steps 3 through 5 for each table you want to add to the dataset.
  8. Save the schema.

    The corresponding class file is regenerated to incorporate the changes you made.

Next Steps

If you need to make changes to the schema, you can use the XML Designer to add, edit, and remove elements.

See Also

Relational Data in XML Schemas | Tables, Columns, Keys, and Constraints in XML Schemas | Nested Relationships in XML | Creating Primary and Unique Keys in XML Schemas | Creating One-to-Many Relationships in XML Schemas and Datasets | XML Schemas and Data | XML Schemas and the XML Designer | Creating XML Schemas and Datasets | XML Files | Introduction to Data Access with ADO.NET | Introduction to Datasets

Show:
© 2015 Microsoft