---
title: "XML Bulk Load Examples (SQLXML)"
description: View detailed examples of the XML Bulk Load functionality in SQKXML 4.0 with XSD and XDR schemas for each example.
author: MikeRayMSFT
ms.author: mikeray
ms.date: "03/17/2017"
ms.prod: sql
ms.prod_service: "database-engine, sql-database"
ms.technology: xml
ms.topic: "reference"
ms.custom: "seo-lt-2019"
helpviewer_keywords:
- "overflow-field annotation"
- "ConnectionCommand property"
- "XMLFragment property"
- "relationship chains [SQLXML]"
- "multiple table bulk loading"
- "examples [SQLXML], XML Bulk Load"
- "overflow data [SQLXML]"
ms.assetid: 970e4553-b41d-4a12-ad50-0ee65d1f305d
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
---
# XML Bulk Load Examples (SQLXML 4.0)
[!INCLUDE [SQL Server Azure SQL Database](../../../includes/applies-to-version/sql-asdb.md)]
The following examples illustrate the XML Bulk Load functionality in Microsoft [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)]. Each example provides an XSD schema and its equivalent XDR schema.
## Bulk Loader Script (ValidateAndBulkload.vbs)
The following script, written in the [!INCLUDE[msCoName](../../../includes/msconame-md.md)] Visual Basic Scripting Edition (VBScript), loads an XML document into the XML DOM; validates it against a schema; and, if the document is valid, executes an XML bulk load to load the XML into a [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] table. This script can be used with each of the individual examples that refer to it later in this topic.
> [!NOTE]
> XML Bulk Load does not throw a warning or an error if no content is uploaded from the data file. Therefore, it is a good practice to validate your XML data file prior to executing a bulk load operation.
```vbs
Dim FileValid
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=MyServer;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
'Validate the data file prior to bulkload
Dim sOutput
sOutput = ValidateFile("SampleXMLData.xml", "", "SampleSchema.xml")
WScript.Echo sOutput
If FileValid Then
' Check constraints and initiate transaction (if needed)
' objBL.CheckConstraints = True
' objBL.Transaction=True
'Execute XML bulkload using file.
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing
End If
Function ValidateFile(strXmlFile,strUrn,strXsdFile)
' Create a schema cache and add SampleSchema.xml to it.
Dim xs, fso, sAppPath
Set fso = CreateObject("Scripting.FileSystemObject")
Set xs = CreateObject("MSXML2.XMLSchemaCache.6.0")
sAppPath = fso.GetFolder(".")
xs.Add strUrn, sAppPath & "\" & strXsdFile
' Create an XML DOMDocument object.
Dim xd
Set xd = CreateObject("MSXML2.DOMDocument.6.0")
' Assign the schema cache to the DOM document.
' schemas collection.
Set xd.schemas = xs
' Load XML document as DOM document.
xd.async = False
xd.Load sAppPath & "\" & strXmlFile
' Return validation results in message to the user.
If xd.parseError.errorCode <> 0 Then
ValidateFile = "Validation failed on " & _
strXmlFile & vbCrLf & _
"=======" & vbCrLf & _
"Reason: " & xd.parseError.reason & _
vbCrLf & "Source: " & _
xd.parseError.srcText & _
vbCrLf & "Line: " & _
xd.parseError.Line & vbCrLf
FileValid = False
Else
ValidateFile = "Validation succeeded for " & _
strXmlFile & vbCrLf & _
"========" & _
vbCrLf & "Contents to be bulkloaded" & vbCrLf
FileValid = True
End If
End Function
```
## A. Bulk loading XML in a table
This example establishes a connection to the instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] that is specified in the ConnectionString property (MyServer). The example also specifies the ErrorLogFile property. Therefore, the error output is saved in the specified file ("C:\error.log"), which you might also decide to change to a different location. Notice also that the Execute method has as its parameters both the mapping schema file (SampleSchema.xml) and the XML data file (SampleXMLData.xml). When the bulk load executes, the Cust table you have created in **tempdb** database will contain new records based upon the contents of the XML data file.
#### To test a sample bulk load
1. Create this table:
```sql
CREATE TABLE Cust(CustomerID int PRIMARY KEY,
CompanyName varchar(20),
City varchar(20));
GO
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. To this file, add the following XSD schema:
```xml
```
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. To this file, add the following XML document:
```xml
1111
Sean Chai
New York
1112
Tom Johnston
Los Angeles
1113
Institute of Art
Chicago
```
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the VBScript code that is provided above at the beginning of this topic. Modify the connection string to provide the appropriate server name. Specify the appropriate path for the files that are specified as parameters to the Execute method.
5. Execute the VBScript code. XML Bulk Load loads the XML into the Cust table.
This is the equivalent XDR schema:
```xml
```
## B. Bulk loading XML data in multiple tables
In this example, the XML document consists of the **\** and **\** elements.
```xml
1111
Sean Chai
NY
1112
Tom Johnston
LA
1113
Institute of Art
```
This example bulk loads the XML data into two tables, **Cust** and **CustOrder**:
- Cust(CustomerID, CompanyName, City)
- CustOrder(OrderID, CustomerID)
The following XSD schema defines the XML view of these tables. The schema specifies the parent-child relationship between the **\** and **\** elements.
```xml
```
XML Bulk Load uses the primary key/foreign key relationship specified above between the **\** and **\** elements to bulk load the data into both tables.
#### To test a sample bulk load
1. Create two tables in **tempdb** database:
```sql
USE tempdb;
CREATE TABLE Cust(
CustomerID int PRIMARY KEY,
CompanyName varchar(20),
City varchar(20));
CREATE TABLE CustOrder( OrderID int PRIMARY KEY,
CustomerID int FOREIGN KEY REFERENCES Cust(CustomerID));
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add the XSD schema that is provided in this example to the file.
3. Create a file in your preferred text or XML editor, and save it as SampleData.xml. Add the XML document that was provided earlier in this example to the file.
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the VBScript code that is provided above at the beginning of this topic. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that are specified as parameters to the Execute method.
5. Execute the VBScript code above. XML Bulk Load loads the XML document into the Cust and CustOrder tables.
This is the equivalent XDR schema:
```xml
```
## C. Using chain relationships in the schema to bulk load XML
This example illustrates how the M:N relationship that is specified in the mapping schema is used by XML Bulk Load to load data in a table that represents an M:N relationship.
For example, consider this XSD schema:
```xml
```
The schema specifies an **\** element with a **\** child element. The **\** element maps to Ord table and the **\** element maps to the Product table in the database. The chain relationship specified on the **\** element identifies a M:N relationship represented by the OrderDetail table. (An order can include many products, and a product can be included in many orders.)
When you are bulk loading an XML document with this schema, records are added to the Ord, Product, and OrderDetail tables.
#### To test a working sample
1. Create three tables:
```sql
CREATE TABLE Ord (
OrderID int PRIMARY KEY,
CustomerID varchar(5));
GO
CREATE TABLE Product (
ProductID int PRIMARY KEY,
ProductName varchar(20));
GO
CREATE TABLE OrderDetail (
OrderID int FOREIGN KEY REFERENCES Ord(OrderID),
ProductID int FOREIGN KEY REFERENCES Product(ProductID),
CONSTRAINT OD_key PRIMARY KEY (OrderID, ProductID));
GO
```
2. Save the schema that is provided above in this example as SampleSchema.xml.
3. Save the following sample XML data as SampleXMLData.xml:
```xml
```
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the VBScript code that is provided above at the beginning of this topic. Modify the connection string to provide the appropriate server and database name. Uncomment the following lines from the source code for this example.
```vbs
objBL.CheckConstraints = True
objBL.Transaction=True
```
5. Execute the VBScript code. XML Bulk Load loads the XML document into the Ord and Product tables.
## D. Bulk loading in identity type columns
This example illustrates how bulk load handles identity type columns. In the example, data is bulk loaded into three tables (Ord, Product, and OrderDetail).
In these tables:
- OrderID in the Ord table is an identity type column
- ProductID in the Product table is an identity type column.
- OrderID and ProductID columns in the OrderDetail are foreign key columns referring to corresponding primary key columns in the Ord and Product tables.
The following are the table schemas for this example:
```
Ord (OrderID, CustomerID)
Product (ProductID, ProductName)
OrderDetail (OrderID, ProductID)
```
In this example of XML Bulk Load, the KeepIdentity property of the BulkLoad object model is set to false. Therefore, [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] generates identity values for the ProductID and OrderID columns in the Product and Ord tables, respectively (any values provided in the documents to be bulk loaded are ignored).
In this case, XML Bulk Load identifies the primary key/foreign key relationship among tables. Bulk Load first inserts records in the tables with the primary key, then propagates the identity value generated by [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] to the tables with foreign key columns. In the following example, XML Bulk Load inserts data in tables in this order:
1. Product
2. Ord
3. OrderDetail
> [!NOTE]
> In order to propagate identity values generated in the Products and Orders tables, the processing logic requires XML Bulk Load to keep track of these values for later insertion into the OrderDetails table. To do that, XML Bulk Load creates intermediate tables, populates the data in these tables, and later removes them.
#### To test a working sample
1. Create these tables:
```
CREATE TABLE Ord (
OrderID int identity(1,1) PRIMARY KEY,
CustomerID varchar(5));
GO
CREATE TABLE Product (
ProductID int identity(1,1) PRIMARY KEY,
ProductName varchar(20));
GO
CREATE TABLE OrderDetail (
OrderID int FOREIGN KEY REFERENCES Ord(OrderID),
ProductID int FOREIGN KEY REFERENCES Product(ProductID),
CONSTRAINT OD_key PRIMARY KEY (OrderID, ProductID));
GO
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add this XSD schema to this file.
```
```
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Add the following XML document.
```
```
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the following VBScript code. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that serve as parameters to the **Execute** method.
```
Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "C:\error.log"
objBL.CheckConstraints = True
objBL.Transaction = False
objBL.KeepIdentity = False
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
Set objBL = Nothing
MsgBox "Done."
```
5. Execute the VBScript code. The XML Bulk Load will load the data into the appropriate tables.
## E. Generating table schemas before bulk loading
XML Bulk Load can optionally generate the tables if they do not exist before bulk loading. Setting the SchemaGen property of the SQLXMLBulkLoad object to TRUE does this. You can also optionally request XML Bulk Load to drop any existing tables and re-create them by setting the SGDropTables property to TRUE. The following VBScript example illustrates the use of these properties.
Also, this example sets two additional properties to TRUE:
- CheckConstraints. Setting this property to TRUE ensures that the data being inserted into the tables does not violate any constraints that have been specified on the tables (in this case the PRIMARY KEY/FOREIGN KEY constraints specified between the Cust and CustOrder tables). If there is a constraint violation, the bulk load fails.
- XMLFragment. This property must be set to TRUE because the sample XML document (data source) contains no single, top-level element (and is thus a fragment).
This is the VBScript code:
```
Dim objBL
Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints=true
objBL.XMLFragment = True
objBL.SchemaGen = True
objBL.SGDropTables = True
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
Set objBL = Nothing
```
#### To test a working sample
1. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add the XSD schema that is provided in the earlier example, "Using chain relationships in the schema to bulk load XML", to the file.
2. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Add the XML document that is provided in the earlier example, "Using chain relationships in the schema to bulk load XML", to the file. Remove the \ element from the document (to make it a fragment).
3. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the VBScript code in this example. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that are specified as parameters to the Execute method.
4. Execute the VBScript code. The XML Bulk Load creates the necessary tables on the basis of the mapping schema that is provided and bulk loads the data in it.
## F. Bulk loading from a stream
The Execute method of the XML Bulk Load object model takes two parameters. The first parameter is the mapping schema file. The second parameter provides the XML data that is to be loaded in the database. There are two ways to pass the XML data to the Execute method of XML Bulk Load:
- Specify the file name as the parameter.
- Pass a stream that contains the XML data.
This example illustrates how to bulk load from a stream.
VBScript first executes a SELECT statement to retrieve customer information from the Customers table in the Northwind database. Because the FOR XML clause is specified (with the ELEMENTS option) in the SELECT statement, the query returns an element-centric XML document of this form:
```
..
..
..
...
```
The script then passes the XML as a stream to the Execute method as its second parameter. The Execute method bulk loads the data into the Cust table.
Because this script sets the SchemaGen property to TRUE and SGDropTables property to TRUE, XML Bulk Load creates the Cust table in the specified database. (If the table already exists, it first drops the table and then re-creates it.)
This is the VBScript example:
```
Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
Set objCmd = CreateObject("ADODB.Command")
Set objConn = CreateObject("ADODB.Connection")
Set objStrmOut = CreateObject ("ADODB.Stream")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
objBL.SchemaGen = True
objBL.SGDropTables = True
objBL.XMLFragment = True
' Open a connection to the instance of SQL Server to get the source data.
objConn.Open "provider=SQLOLEDB;server=(local);database=tempdb;integrated security=SSPI"
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = "SELECT CustomerID, CompanyName, City FROM Customers FOR XML AUTO, ELEMENTS"
' Open the return stream and execute the command.
Const adCRLF = -1
Const adExecuteStream = 1024
objStrmOut.Open
objStrmOut.LineSeparator = adCRLF
objCmd.Properties("Output Stream").Value = objStrmOut
objCmd.Execute , , adExecuteStream
objStrmOut.Position = 0
' Execute bulk load. Read source XML data from the stream.
objBL.Execute "SampleSchema.xml", objStrmOut
Set objBL = Nothing
```
The following XSD mapping schema provides the necessary information to create the table:
```
```
This is equivalent XDR schema:
```
```
### Opening a Stream on an Existing File
You can also open a stream on an existing XML data file and pass the stream as a parameter to the Execute method (instead of passing the file name as the parameter).
This is a Visual Basic example of passing a stream as the parameter:
```
Private Sub Form_Load()
Dim objBL As New SQLXMLBulkLoad
Dim objStrm As New ADODB.Stream
Dim objFileSystem As New Scripting.FileSystemObject
Dim objFile As Scripting.TextStream
MsgBox "Begin BulkLoad..."
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
objBL.SchemaGen = True
objBL.SGDropTables = True
' Here again a stream is specified that contains the source data
' (instead of the file name). But this is just an illustration.
' Usually this is useful if you have an XML data
' stream that is created by some other means that you want to bulk
' load. This example starts with an XML text file, so it may not be the
' best to use a stream (you can specify the file name directly).
' Here you could have specified the file name itself.
Set objFile = objFileSystem.OpenTextFile("c:\SampleData.xml")
objStrm.Open
objStrm.WriteText objFile.ReadAll
objStrm.Position = 0
objBL.Execute "c:\SampleSchema.xml", objStrm
Set objBL = Nothing
MsgBox "Done."
End Sub
```
To test the application, use the following XML document in a file (SampleData.xml) and the XSD schema that is provided in this example:
This is the XML source data (SampleData.xml):
```
1111
Hanari Carnes
NY
1112
Toms Spezialitten
LA
1113
Victuailles en stock
```
This is the equivalent XDR schema:
```
```
## G. Bulk loading in overflow columns
If the mapping schema specifies an overflow column by using the **sql:overflow-field** annotation, XML Bulk Load copies all unconsumed data from the source document into this column.
Consider this XSD schema:
```
```
The schema identifies an overflow column (OverflowColumn) for the Cust table. As a result, all unconsumed XML data for each **\** element is added to this column.
> [!NOTE]
> All abstract elements (elements for which **abstract="true"** is specified) and all prohibited attributes (attributes for which **prohibited="true"** is specified) are considered overflow by XML Bulk Load and are added to the overflow column, if specified. (Otherwise, they are ignored.)
#### To test a working sample
1. Create two tables in **tempdb** database:
```
USE tempdb;
CREATE TABLE Cust (
CustomerID int PRIMARY KEY,
CompanyName varchar(20) NOT NULL,
City varchar(20) DEFAULT 'Seattle',
OverflowColumn nvarchar(200));
GO
CREATE TABLE CustOrder (
OrderID int PRIMARY KEY,
CustomerID int FOREIGN KEY
REFERENCES Cust(CustomerID));
GO
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add the XSD schema that is provided in this example to the file.
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Add the following XML document to the file:
```
1111
Hanari Carnes
garbage in overflow
1112
Toms Spezialitten
1113
Victuailles en stock
```
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the following Microsoft Visual Basic Scripting Edition (VBScript) code. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that are specified as parameters to the Execute method.
```
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing
```
5. Execute the VBScript code.
This is the equivalent XDR schema:
```
```
## H. Specifying the file path for temp files in transaction mode
When you are bulk loading in transaction mode (that is, when the Transaction property is set to TRUE), you also must set the TempFilePath property when either of the following conditions is true:
- You are bulk loading to a remote server.
- You want to use an alternate local drive or folder (one other than the path that is specified by the TEMP environment variable) to store the temporary files that are created in the transaction mode.
For example, the following VBScript code bulk loads data from the SampleXMLData.xml file into the database tables in transaction mode. The TempFilePath property is specified to set the path for the temporary files that are generated in transaction mode.
```
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
objBL.Transaction=True
objBL.TempFilePath="\\Server\MyDir"
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing
```
> [!NOTE]
> The temporary file path must be a shared location that is accessible to the service account of the target instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] and to the account that is running the bulk load application. Unless you are bulk loading on a local server, the temporary file path must be a UNC path (such as \\\servername\sharename).
#### To test a working sample
1. Create this table in **tempdb** database:
```
USE tempdb;
CREATE TABLE Cust ( CustomerID uniqueidentifier,
LastName varchar(20));
GO
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add the following XSD schema to the file:
```
```
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Add the following XML document to the file:
```
```
4. Create a file in your preferred text or XML editor, and save it as ValidateAndBulkload.vbs. To this file, add the following VBScript code. Modify the connection string to provide the appropriate server and database name. Specify the appropriate path for the files that are specified as parameters to the Execute method. Also specify the appropriate path for the TempFilePath property.
```
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=localhost;database=tempdb;integrated security=SSPI"
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
objBL.Transaction=True
objBL.TempFilePath="\\server\folder"
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing
```
5. Execute the VBScript code.
The schema must specify the corresponding **sql:datatype** for the **CustomerID** attribute when the value for **CustomerID** is specified as a GUID that includes braces ({ and }), such as:
```
```
This is the updated schema:
```
```
When **sql:datatype** is specified identifying the column type as **uniqueidentifier**, the bulk load operation removes the braces ({ and }) from the **CustomerID** value before inserting it in the column.
This is the equivalent XDR schema:
```
```
## I. Using an existing database connection with the ConnectionCommand property
You can use an existing ADO connection to bulk load XML. This is useful if XML Bulk Load is just one of many operations that will be performed on a data source.
The ConnectionCommand property enables you to use an existing ADO connection by using an ADO command object. This is illustrated in the following Visual Basic example:
```
Private Sub Form_Load()
Dim objBL As New SQLXMLBulkLoad4
Dim objCmd As New ADODB.Command
Dim objConn As New ADODB.Connection
'Open a connection to an instance of SQL Server.
objConn.Open "provider=SQLOLEDB;data source=(local);database=tempdb;integrated security=SSPI"
'Ask the Command object to use the connection just established.
Set objCmd.ActiveConnection = objConn
'Tell Bulk Load to use the active command object that is using the Connection obj.
objBL.ConnectionCommand = objCmd
objBL.ErrorLogFile = "c:\error.log"
objBL.CheckConstraints = True
'The Transaction property must be set to True if you use ConnectionCommand.
objBL.Transaction = True
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
Set objBL = Nothing
End Sub
```
#### To test a working sample
1. Create two tables in **tempdb** database:
```
USE tempdb;
CREATE TABLE Cust(
CustomerID varchar(5) PRIMARY KEY,
CompanyName varchar(30),
City varchar(20));
GO
CREATE TABLE CustOrder(
CustomerID varchar(5) references Cust (CustomerID),
OrderID varchar(5) PRIMARY KEY);
GO
```
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Add the following XSD schema to the file:
```
```
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Add the following XML document to the file:
```
1111
Hanari Carnes
NY
1112
Toms Spezialitten
LA
1113
Victuailles en stock
```
4. Create a Visual Basic (Standard EXE) application and the preceding code. Add these references to the project:
```
Microsoft XML BulkLoad for SQL Server 4.0 Type Library
Microsoft ActiveX Data objects 2.6 Library
```
5. Execute the application.
This is the equivalent XDR schema:
```
```
## J. Bulk loading in xml Data Type columns
If the mapping schema specifies a [xml data type](../../../t-sql/xml/xml-transact-sql.md) column by using the **sql:datatype="xml"** annotation, XML Bulk Load can copy XML child elements for the mapped field from the source document into this column.
Consider the following XSD schema, which maps a view of the Production.ProductModel table in the AdventureWorks sample database. In this table, the CatalogDescription field of **xml** data type is mapped to a **\** element using the **sql:field** and **sql:datatype="xml"** annotations.
```
```
#### To test a working sample
1. Verify that the AdventureWorks sample database is installed.
2. Create a file in your preferred text or XML editor, and save it as SampleSchema.xml. Copy the XSD schema above and paste it into the file and save it.
3. Create a file in your preferred text or XML editor, and save it as SampleXMLData.xml. Copy the following XML document below and paste it into the file and save it in the same folder as was used for the previous step.
```
Mountain-100 (2005 model)
Our top-of-the-line competition mountain bike.
Performance-enhancing options include the innovative HL Frame,
super-smooth front suspension, and traction for all terrain.
AdventureWorks
2002-2005
HTTP://www.Adventure-works.com
These are the product highlights.
3 years
parts and labor
10 years
maintenance contract available through your dealer or any AdventureWorks retail store.
High performance wheels.
Anatomic design and made from durable leather for a full-day of riding in comfort.
Top-of-the-line clipless pedals with adjustable tension.Each frame is hand-crafted in our Bothell facility to the optimum diameter
and wall-thickness required of a premium mountain frame.
The heat-treated welded aluminum frame has a larger diameter tube that absorbs the bumps. Triple crankset; alumunim crank arm; flawless shifting.
front
small
118
These are the product specifications.
Almuminum AlloyAvailable in most colorsMountain bikeAdvanced to Professional riders
```
4. Create a file in your preferred text or XML editor, and save it as BulkloadXml.vbs. Copy the following VBScript code and paste it into the file. Save it in the same folder as was used for the previous XML data and schema files.
```
set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "provider=SQLOLEDB;data source=MyServer;database=AdventureWorks;integrated security=SSPI"
Dim fso, sAppPath
Set fso = CreateObject("Scripting.FileSystemObject")
sAppPath = fso.GetFolder(".")
objBL.ErrorLogFile = sAppPath & "\error.log"
'Execute XML bulkload using file.
objBL.Execute "SampleSchema.xml", "SampleXMLData.xml"
set objBL=Nothing
```
5. Execute the BulkloadXml.vbs script.