Re: Import XML from Command-Line into SQL

From: Sean (sean_cottrell_at_hotmail.com)
Date: 08/23/04


Date: Mon, 23 Aug 2004 07:29:33 -0700

Graeme,

Sorry forgot to post as myself. Please see my first
reply listed as anonymous.

Thanks,

Sean

>-----Original Message-----
>I'd probably create a mapping schema and a VB Script
that uses the SQL XML
>Bulk Load component to bulk load the data. Download
SQLXML
>(http://www.microsoft.com/downloads/details.aspx?
familyid=4c8033a9-cf10-4e22-8004-
477098a407ac&displaylang=en)
>and have a look at the documentation. Here's a simple
example to get you
>started (It loads data into the Categories and Products
tables in the
>Northwind database):
>
>XML file (Catalog.xml):
><?xml version="1.0" ?>
><Catalog>
> <Category CategoryID="99">
> <CategoryName>Scottish Foods</CategoryName>
> <Description>Traditional food from
Scotland</Description>
> <Product ProductID="101">
> <ProductName>Porridge</ProductName>
> <UnitPrice>16</UnitPrice>
> </Product>
> <Product ProductID="102">
> <ProductName>Haggis</ProductName>
> <UnitPrice>19</UnitPrice>
> </Product>
> </Category>
> <Category CategoryID="100">
> <CategoryName>Scottish Drinks</CategoryName>
> <Description>Traditional drinks from
Scotland</Description>
> <Product ProductID="103">
> <ProductName>Single Malt Whisky</ProductName>
> <UnitPrice>100</UnitPrice>
> </Product>
> </Category>
></Catalog>
>
>Schema file (Catalog.xsd):
><?xml version="1.0" ?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:sql="urn:schemas-microsoft-
com:mapping-schema">
> <xsd:element name="Catalog" sql:is-constant="1">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="Category"
sql:relation="Categories">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="CategoryName"
type="xsd:string"
> sql:field="CategoryName"
>sql:datatype="nvarchar(15)" />
> <xsd:element name="Description"
type="xsd:string"
> sql:field="Description"
sql:datatype="ntext" />
> <xsd:element name="Product"
sql:relation="Products">
> <xsd:annotation>
> <xsd:appinfo>
> <sql:relationship parent="Categories"
> parent-
key="CategoryID"
> child="Products"
> child-
key="CategoryID" />
> </xsd:appinfo>
> </xsd:annotation>
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="ProductName"
type="xsd:string"
> sql:field="ProductName"
>sql:datatype="nvarchar(40)" />
> <xsd:element name="UnitPrice"
type="xsd:decimal"
> sql:field="UnitPrice"
sql:datatype="money"
>/>
> </xsd:sequence>
> <xsd:attribute name="ProductID"
type="xsd:integer"
> sql:field="ProductID"
sql:datatype="int" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="CategoryID"
type="xsd:integer"
> sql:field="CategoryID"
sql:datatype="int" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
></xsd:schema>
>
>VB Script:
>Set objBulkLoad = CreateObject
("SQLXMLBulkLoad.SQLXMLBulkLoad")
>objBulkLoad.ConnectionString = _
> "provider=SQLOLEDB;Server=
(local);database=Northwind;" & _
> "Integrated Security=SSPI;"
>objBulkLoad.Execute "Catalog.xsd", "Catalog.xml"
>Set objBulkLoad = Nothing
>MsgBox "Catalog Imported"
>
>
>Hope that helps,
>Graeme
>
>--
>----
>Graeme Malcolm
>Principal Technologist
>Content Master Ltd.
>www.contentmaster.com
>
>
>"Sean" <sean_cottrell@hotmail.com> wrote in message
>news:aadd01c4888c$71c28930$a501280a@phx.gbl...
>HI,
>
>I am try to accomplish the following:
>
>Every day I will get a random number of XML files with a
>random number of row entries. each of these files will
>have a different file name but be in a specific file name
>format such as file1.xml,file2.xml, etc. These files will
>be "dumped" to a network drive at random times. We
>already have a program written that will monitor this
>directory and when I file gets "dumped" into it, will
>fire of a script.
>
>I am looking for the best way to take each of these .xml
>files and import them into a MS SQL Table. The files are
>very simple containing only 9 columns per row of data.
>Also, we would prefer that this script execute from a
>remote server other than the server that is running MS
>SQL.
>
>Can anybody suggest the best way to do this?
>
>
>.
>



Relevant Pages

  • Re: DOM-scripting -- FF problem
    ... A document can not be "served as XML"; ... If the document type was an XHTML document type, ... script code which would be necessary in order to achieve a Valid document ... markup characters are regarded literal characters without ...
    (comp.lang.javascript)
  • Re: WINDOWS MEDIA FILE EDITOR - HELP!!!
    ... before (You might want to look at programs like microsofts XML Notepad ... The actual file format can be defined by a DTD ... >but it is all our clients protocol supports) and with this, been encoding asf ... It doesn't recognize the same script file as I once used...get ...
    (microsoft.public.windowsmedia)
  • Re: WSH in VS.NET 2003?
    ... or will wsh xml include a ... Get the "TechNet Script Center Sample Scripts" ... Other|Useful Scripting Technologies|Saving Data in XML Format ... There is no schema for getting MS. ...
    (microsoft.public.scripting.wsh)
  • Re: Import XML from Command-Line into SQL
    ... Set objBL = CreateObject ... >I'd probably create a mapping schema and a VB Script ... that uses the SQL XML ...
    (microsoft.public.sqlserver.xml)
  • Re: Excel 2007 Menus - Ron De Bruin please
    ... I find that the "for one workbook" version is saved with the file, so I was wrong about that. ... |> manually attach the macro to it. ... |> XML is not a script. ...
    (microsoft.public.excel.programming)

Loading