SQL Server2000 parsing XML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.