[quoted text, click to view] > I noticed all the examples in published books, as well as BOL,
conveniently
> strip these lines and replace them with <ROOT>. How do you read in real
> XML files ? Real XML files do not have the tag <ROOT> in the first
line,
> they begin with <?xml version=....
>
> I do not get any errors, it just returns 0 rows...
The first example below was gleaned from the Books Online. I added
processing instruction <?xml version="1.0" encoding="UTF-8"?> and change the
ROOT element to 'Customers'. Please post your code and sample XML document
if you still need help.
DECLARE @hdoc int
DECLARE @doc varchar(1000)
SET @doc ='
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
<Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00">
<OrderDetail OrderID="10248" ProductID="11" Quantity="12"/>
<OrderDetail OrderID="10248" ProductID="42" Quantity="10"/>
</Order>
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
<Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00">
<OrderDetail OrderID="10283" ProductID="72" Quantity="3"/>
</Order>
</Customer>
</Customers>'
EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc
SELECT *
FROM OPENXML (@hdoc, '/Customers/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
EXEC sp_xml_removedocument @hdoc
GO
[quoted text, click to view] > Are there easier ways to bring in an XML document into a table using
> transact SQL, or VBscript within a DTS package ?
The VBScript example below loads XML text from a file into a table: It uses
the XML DOM to ensure the document is well-formed.
--sample table
CREATE TABLE dbo.MyTable
(
FileName nvarchar(255) NOT NULL,
MyXml ntext
)
'VBScript example
fileName = "C:\MyXmlFiles\MyXmlFile.xml"
Set myxmlDocument = CreateObject("Msxml2.DomDocument.4.0")
Set myConnection = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command")
myConnection.Open "Provider=SQLOLEDB;" & _
"Data Source=DBDELTA1;" & _
"Integrated Security=SSPI;" & _
"Initial Catalog=MyDatabase"
Set myxmlDocument = CreateObject("Msxml2.DomDocument.4.0")
myxmlDocument.Load(fileName)
myCommand.CommandText = "INSERT INTO MyTable VALUES(?, ?)"
myCommand.ActiveConnection = myConnection
Set myFileNameParameter = myCommand.CreateParameter( _
"@MyFileNameParameter", 203, 1, 255, fileName)
myCommand.Parameters.Append myFileNameParameter
Set myXmlParameter = myCommand.CreateParameter( _
"@MyXmlParameter", 203, 1, 1000000, myxmlDocument.Xml)
myCommand.Parameters.Append myXmlParameter
myXmlParameter.Value = myxmlDocument.Xml
myCommand.Execute
--
Hope this helps.
Dan Guzman
SQL Server MVP
[quoted text, click to view] "rob" <rwc1960@bellsouth.net> wrote in message
news:jbCmc.135637$Yw5.104143@bignews4.bellsouth.net...
> New to xml..
>
> I am trying to read in A REAL xml file using the sp_xml_preparedocument
and
> OPENXML statement as shown in BOL. I am not trying to read in a PLAY xml
> file with the stuff at the top stripped out ( i.e., <?xml version=...
> <UpdateProcee xmlns= etc.)
>
> I cannot seem to make it work unless I strip out these the top 2 lines and
> replace them with a <ROOT> tag...
>
> I noticed all the examples in published books, as well as BOL,
conveniently
> strip these lines and replace them with <ROOT>. How do you read in real
> XML files ? Real XML files do not have the tag <ROOT> in the first
line,
> they begin with <?xml version=....
>
> I do not get any errors, it just returns 0 rows...
>
> Thanks !
>
> Are there easier ways to bring in an XML document into a table using
> transact SQL, or VBscript within a DTS package ?
>
>
>
>
>