Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 25th, 2008, 07:35 PM
Authorized User
Join Date: Jun 2007
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to import XML into SQL Server

I have a XML File below,

<?xml version="1.0" encoding="utf-8"?>
<Employees xmlns="http://tempuri.org/MySchema.xsd">
   <Employee ID="1">
   <Employee ID="2">

I have created a table as below in sql server,
   ID nvarchar(10),
   FirstName NVARCHAR(50),
   LastName NVARCHAR(50),
PhoneNumber NVARCHAR(50),
EmailAddress NVARCHAR(100))

I am trying to import the xml data into the sql table using the schema,the schema is as below

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://startrack:xml-data"

   <xs:element name="Employees" sql:is-constant="1">
      <xs:choice minOccurs="1" maxOccurs="*">
         <xs:element name="Employee" type="Employee" sql:relation="Employee"/>
      <xs:complexType name="Employee" >
            <xs:element name="FirstName" type="xs:string"
                        minOccurs="1" maxOccurs="1" sql:field="FirstName"/>
            <xs:element name="LastName" type="xs:string"
                        minOccurs="1" maxOccurs="1" sql:field="LastName"/>
            <xs:element name="PhoneNumber" type="xs:string"
                        minOccurs="1" maxOccurs="1" sql:field="PhoneNumber" />
            <xs:element name="EmailAddress" type="xs:string"
                        minOccurs="1" maxOccurs="1" sql:field="EmailAddress" />
         <xs:attribute name="ID" type="xs:string" />

I import by running the below script in the DTS, The PROBLEM IS THAT the DTS runs without any error but the data is not imported to the table.

Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.3.0")
    objBL.ConnectionString = "provider=SQLOLEDB.1;data source=Myserver;database=MyDB;uid=MYUSER;pwd=MYPWD "
    objBL.ErrorLogFile = "z:\error.log"
    objBL.Execute "z:\employee_mapping.xml", "z:\employee.xml"
    Set objBL = Nothing

Is there any syntax that i missed in the schema?

Any help appreciated. I am a Newbie to XML and Schema's.


  #2 (permalink)  
Old February 26th, 2008, 06:02 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

Your schema isn't a valid schema because your namespaces are not correctly defined:

The following are the correct namespace declarations:


After you change those to the correct names you might get other errors but hopefully you can work them out on your own.

/- Sam Judson : Wrox Technical Editor -/

Similar Threads
Thread Thread Starter Forum Replies Last Post
Import data from sql server using biztalk server kaushalparik Biztalk 0 July 22nd, 2008 06:16 AM
Import a XML file into SQL Server tables Cha BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 April 1st, 2008 09:54 PM
Import XML to SQL table Colonel Angus SQL Server 2000 4 March 23rd, 2007 08:37 AM
Import XML and its attribute into SQL server 2000 khautinh C# 0 April 13th, 2005 09:57 AM
How to import xml into SQL database thru ASP porsrari Classic ASP XML 4 October 14th, 2003 11:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.