A simple example of using “sp_xml_preparedocument” stored procedure


A small example of how to use the sp_xml_preparedocument stored procedure. “sp_xml_preparedocument” reads the Extensible Markup Language (XML) text, parses the text by using the MSXML parser and provides the parsed document in a state ready for consumption.

DECLARE @hdoc     int
DECLARE @doc      varchar(2000)

SET @doc = ''
EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc

SELECT * FROM OPENXML( @hdoc, '/ROOT/Customer/Order/OrderDetail',2)
WITH (      OrderID int '@OrderID',
            CustomerID varchar(10) '../@CustomerID',
            OrderDate datetime '../@OrderDate',
            ProdID int '@ProductID',
            Qty int '@Quantity' )

EXEC sp_xml_removedocument @hdoc
GO
Advertisements

One thought on “A simple example of using “sp_xml_preparedocument” stored procedure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s