Parsing XML data in Sql server

--OPENXML parses the XML data in SQL Server in an efficient manner. It’s primary ability is to insert XML data to the RDB. It is also possible to query the data by using OpenXML.
--The path of the XML element needs to be specified by using ‘xpath’.
--The following is a procedure for retrieving xml data:
DECLARE @index int
DECLARE @xmlString varchar(8000)
SET @xmlString ='<Persons>
<Person id="15201">
<Name>Prasanth</Name>
<PhoneNo>9343463943</PhoneNo>
</Person>
<Person id="15202">
<Name>Laasya</Name>
<PhoneNo>9342673212</PhoneNo>
</Person>
</Persons>'
EXEC sp_xml_preparedocument @index OUTPUT, @xmlString

SELECT * FROM OPENXML (@index, 'Persons/Person')

 WITH  (id varchar(10), Name varchar(100) 'Name' , PhoneNo varchar(50) 'PhoneNo')
EXEC sp_xml_removedocument @index

--The above code snippet results the following:
--15201 Prasanth 9343463943
--15202 Laasya   9342673212

Comments

Popular posts from this blog

HOW TO Use the NumericUpDown Control

How To Get IP & Locations details of client machine in asp.net

Get control name in Page_Load event after post back by any control