Declare @ hdoc int -- document handle
Declare @ xmlstring varchar (200) -- XML string
Set @ xmlstring = '<? XML version = "1.0"?>
<Root>
<User id = "1" name = "sbqcel"/>
<User id = "2" name = "peaceli"/>
<User id = "3" name = "sheepchang"/>
</Root>'
-- Analyze the XML string using the system stored procedure sp_xml_preparedocument
Exec sp_xml_preparedocument @ hdoc output, @ xmlstring
-- Use openxml to query data from the internal cache of SQL Server
Select * From openxml (@ hdoc, n'/root/user ')
With
(
Id int,
Name varchar (10)
)
-- Use the system stored procedure sp_xml_removedocument to release memory
Exec sp_xml_removedocument @ hdoc
Declare @ hdoc int -- document handle
Declare @ xmlstring varchar (200) -- XML string
Set @ xmlstring = '<? XML version = "1.0"?>
<Root>
<User id = "1" name = "sbqcel"/>
<User id = "2" name = "peaceli"/>
<User id = "3" name = "sheepchang"/>
</Root>'
-- Analyze the XML string using the system stored procedure sp_xml_preparedocument
Exec sp_xml_preparedocument @ hdoc output, @ xmlstring
-- Use openxml to query data from the internal cache of SQL Server
Select * From openxml (@ hdoc, n'/root/user ')
With
(
Id int,
Name varchar (10)
)
-- Use the system stored procedure sp_xml_removedocument to release memory
Exec sp_xml_removedocument @ hdoc
Declare @ hdoc int -- document handle
Declare @ xmlstring varchar (200) -- XML string
Set @ xmlstring = '<? XML version = "1.0"?>
<Root>
<User id = "1" name = "sbqcel"/>
<User id = "2" name = "peaceli"/>
<User id = "3" name = "sheepchang"/>
</Root>'
-- Analyze the XML string using the system stored procedure sp_xml_preparedocument
Exec sp_xml_preparedocument @ hdoc output, @ xmlstring
-- Use openxml to query data from the internal cache of SQL Server
Select * From openxml (@ hdoc, n'/root/user ')
With
(
Id int,
Name varchar (10)
)
-- Use the system stored procedure sp_xml_removedocument to release memory
Exec sp_xml_removedocument @ hdoc