--- title: "Default Mapping-XSD Elements-Attributes to Tables-Columns (SQLXML 4.0) | Microsoft Docs" ms.custom: "" ms.date: "03/17/2017" ms.prod: "sql-server-2016" ms.reviewer: "" ms.suite: "" ms.technology: - "dbe-xml" ms.tgt_pltfrm: "" ms.topic: "reference" helpviewer_keywords: - "XSD schemas [SQLXML], mapping attributes and elements" - "mapping schema [SQLXML], default mapping" - "element mapping [SQLXML], default mapping" - "element mapping [SQLXML]" - "table mapping [SQLXML]" - "annotated XSD schemas, mapping attributes and elements" - "table/view mapping [SQLXML]" - "column mapping [SQLXML]" - "attribute mapping [SQLXML], default mapping" - "default schema mapping" - "table mapping [SQLXML], default mapping" - "testing XPath query against schema" - "xml data type [SQL Server], SQLXML" - "table/view mapping [SQLXML], default mapping" - "element/attribute mapping [SQLXML]" ms.assetid: 9a18e92a-6cfb-4a14-993a-663a95aabb63 caps.latest.revision: 32 author: "douglaslMS" ms.author: "douglasl" manager: "jhubbard" --- # Default Mapping of XSD Elements and Attributes to Tables and Columns (SQLXML 4.0) By default, an element of complex type in an XSD annotated schema maps to the table (view) with the same name in the specified database, and an element or attribute of simple type maps to the column with the same name in the table. ## Examples To create working samples using the following examples, you must meet certain requirements. For more information, see [Requirements for Running SQLXML Examples](../../relational-databases/sqlxml/requirements-for-running-sqlxml-examples.md). ### A. Specifying default mapping In this example, no annotations are specified in the XSD schema. The **\** element is of complex type and, therefore, maps by default to the Person.Contact table in the AdventureWorks database. All the attributes (ContactID, FirstName, LastName) of the **\** element are of simple type and map by default to columns with the same names in the Person.Contact table. ``` ``` ##### To test a sample XPath query against the schema 1. Copy the schema code above and paste it into a text file. Save the file as MySchema.xml. 2. Copy the following template and paste it into a text file. Save the file as MySchemaT.xml in the same directory where you saved MySchema.xml. ``` /Person.Contact ``` The directory path specified for the mapping schema (MySchema.xml) is relative to the directory where the template is saved. An absolute path also can be specified, for example: ``` mapping-schema="C:\SqlXmlTest\MySchema.xml" ``` 3. Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the template. For more information, see [Using ADO to Execute SQLXML 4.0 Queries](../../relational-databases/sqlxml/using-ado-to-execute-sqlxml-4-0-queries.md). Here is the partial result set: ``` ... ``` ### B. Mapping an XML element to a database column In this example, default mapping also takes place because no annotations are used. The **\** element is of complex type and maps to the table with the same name in the database. The elements **\** and **\** and the **EmployeeID** attribute are of simple type and, therefore, map to the columns with the same names. The only difference between this and the previous example are that elements are used for mapping the FirstName and LastName fields. ``` ``` ##### To test a sample XPath query against the schema 1. Copy the schema code above and paste it into a text file. Save the file as MySchemaElements.xml. 2. Create the following template (MySchemaElementsT.xml), and save it in the same directory used in the previous step. ``` /Person.Contact ``` The directory path specified for the mapping schema is relative to the directory where the template is saved. An absolute path also can be specified, for example: ``` mapping-schema="C:\SqlXmlTest\MySchemaElements.xml" ``` 3. Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the template. For more information, see [Using ADO to Execute SQLXML 4.0 Queries](../../relational-databases/sqlxml/using-ado-to-execute-sqlxml-4-0-queries.md). Here is the partial result set: ``` Gustavo Achong ... ``` ### C. Mapping an XML element to an XML data type column In this example, default mapping also takes place because no annotations are used. The **\** element is of complex type and maps to the table with the same name in the database. The **ProductModelID** attribute is of simple type and, therefore, map to the columns with the same names. The only difference between this and the previous examples is that the **\** element is mapping to a column that uses the **xml** data type by using the **xsd:anyType** type. ``` ``` The **xml** data type was introduced in [!INCLUDE[ssVersion2005](../../includes/ssversion2005-md.md)]. ##### To test a sample XPath query against the schema 1. Copy the schema code above and paste it into a text file. Save the file as MySchemaXmlAnyElements.xml. 2. Create the following template (MySchemaXmlAnyElementsT.xml), and save it in the same directory used in the previous step. ``` /Production.ProductModel[@ProductModelID=7] ``` The directory path specified for the mapping schema is relative to the directory where the template is saved. An absolute path also can be specified, for example: ``` mapping-schema="C:\SqlXmlTest\MySchemaXmlAnyElements.xml" ``` 3. Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the template. For more information, see [Using ADO to Execute SQLXML 4.0 Queries](../../relational-databases/sqlxml/using-ado-to-execute-sqlxml-4-0-queries.md). Here is the partial result set: ``` ... ``` ## See Also [Annotated Schema Security Considerations (SQLXML 4.0)](../../relational-databases/sqlxml-annotated-xsd-schemas-xpath-queries/security/annotated-schema-security-considerations-sqlxml-4-0.md) [XML Data (SQL Server)](../../relational-databases/xml/xml-data-sql-server.md) [xml Data Type Support in SQLXML 4.0](../../relational-databases/sqlxml/xml-data-type-support-in-sqlxml-4-0.md)