Re: Importing XML into SQL using DTS
- From: "Bertan ARI [MSFT]" <bertan@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 17:49:51 -0700
Try to use attributes property on Dom nodes to get the values of attributes:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/75e7840a-e81d-4c42-ab63-9a65757ceb24.asp
--
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Fec" <Fec@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E454BA66-8786-403D-BC80-406028CCFDAE@xxxxxxxxxxxxxxxx
>I need to import large XML files into an SQL table.
>
> My XML experience is minimal....
>
> My current DTS script can import xml files which are more structured
> (using
> NODES) and works fine. How ever i need to modify it to look at Attributes
> instead of nodes.
> It looks like this:
> '**********************************************************************
> ' Visual Basic ActiveX Script
> '************************************************************************
>
> Function Main()
> Dim objXMLDOM
> Dim objNodes
> Dim objBookNode
>
> Dim objADORS
> Dim objADOCnn
>
> Const adOpenKeyset = 1
> Const adLockOptimistic = 3
>
> Set objXMLDOM = CreateObject("MSXML2.DOMDocument.4.0")
> objXMLDOM.async = False
> objXMLDOM.validateOnParse = False
>
> 'No error handling done
> objXMLDOM.load
> "U:\2-Data\RStation\Unprocessed\bns_usage_2005-05-16_bns2ha.xml"
>
> Set objNodes = objXMLDOM.selectNodes("/Books/Book")
>
> Set objADOCnn = CreateObject("ADODB.Connection")
> Set objADORS = CreateObject("ADODB.Recordset")
>
> objADOCnn.Open
> "PROVIDER=SQLOLEDB;SERVER=UKIW0004921G\LOCAL;UID=sa;PWD=bigbird;DATABASE=ImportXML;"
> objADORS.Open "SELECT * FROM tmpImportXML WHERE 1 = 2", objADOCnn,
> adOpenKeyset, adLockOptimistic
>
> For Each objBookNode In objNodes
> With objADORS
> .AddNew
> .fields("BookTitle") =
> objBookNode.selectSingleNode("Title").nodeTypedValue
> .fields("Publisher") =
> objBookNode.selectSingleNode("Publisher").nodeTypedValue
> .fields("DateOfPurchase") =
> objBookNode.selectSingleNode("DateOfPurchase").nodeTypedValue
>
> .Update
> End With
> Next
> objADORS.Close
> objADOCnn.Close
>
> Main = DTSTaskExecResult_Success
>
> End Function
>
> #################
>
> How do i modify it to look at an XML file structured using Attributes?
>
> ...XML File looks like
>
> The xml structure looks like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <usageFile source="abc" countRetrievals="12345" countSearches="0"
> fileStart="2005-05-16T05:46:36" fileEnd="2005-05-16T07:00:00">
>
> <BookTitle="abc123" Publisher="abcdef"
> DateOfPurchase="2005-05-16T05:45:36"/>
> --
>
>
> Thanks for the help
.
- References:
- Importing XML into SQL using DTS
- From: Fec
- Importing XML into SQL using DTS
- Prev by Date: Re: Import XML need to read attributes
- Next by Date: Re: Annotated schema with views?
- Previous by thread: Re: Importing XML into SQL using DTS
- Next by thread: FOR XML EXPLICIT into Database field
- Index(es):
Relevant Pages
|