This documentation is archived and is not being maintained.

Creating Nested Relationships in XML Schemas

Visual Studio .NET 2003

You create a schema with nested relationships when XML data is represented by parent elements that contain nested child elements. For more information, see Nested Relationships in XML.

Tip   If you have access to an XML file (.xml) that contains the structured data that your application needs to validate then creating a schema can be accomplished by following the instructions for Creating XML Schemas from XML Files.

To construct a schema to validate nested data

  1. Create the individual tables to represent the different hierarchies of data that your XML represents. For more information, see Creating Tables in XML Schemas.
  2. Select the table that represents the nested child element and drag and drop it onto the table that represents the parent element.
  3. If you have any tables that represent nested child elements, repeat Step 2.

The following example shows how to construct an XML Schema that validates nested data. In a nested relationship, the OrderDetails table is a nested child of the Orders table, which are both nested children of the Customers table.

   <CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
            <ShipVia>International Air</ShipVia>

To create a schema to illustrate a nested relationship

  1. Following the instructions in the section Creating Tables in XML Schemas and create three tables. For this example there is no need to define columns, just create the tables and name them: Customers, Orders, and OrderDetails.
  2. Click and drag the header of the Orders table and drop it onto the Customers table.

    An Orders column appears in the Customers table named Orders, and a line appears connecting the two tables.

  3. Click and hold the header of the OrderDetails table and drop it onto the Orders table.

    An OrderDetails column appears in the Orders table named OrderDetails, and a line appears connecting the two tables.

    You can see the nested relationship illustrated on the designer by the lines that connect all three tables together, as well as the existence of the nested child tables as columns in each parent table throughout the hierarchy.

You have just created a schema that represents a nested relationship. More importantly switch to XML view (click the XML tab on the bottom of the design surface) and you can now see the apparent nested structure of the schema.

See Also

Relational Data in XML Schemas | Tables, Columns, Keys, and Constraints in XML Schemas | Nested Relationships in XML | Creating Tables in XML Schemas | Creating Primary and Unique Keys in XML Schemas | XML Schemas and Data | XML Schemas and the XML Designer | Creating XML Schemas and Datasets | XML Files