Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help needed on XML

Author  Topic 

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2010-02-26 : 07:31:18
Hi

I have a xml string . How can i get the attributes and the node values like below

Ex:

<Employee>
<id>1</id>
<name>xxx</name>
<marks>45</mark>
<class>7</class>
</Employee>

Result:

Attribute Name Value
ID 1
Name xxx
marks 45
class 7

Kindly help me ASAP.


Thanks

Jack

shaik.zakeer
Posting Yak Master

117 Posts

Posted - 2010-03-08 : 11:04:01
hi

i found the solution for the above prob

declare @xml xml
set @xml = '<Employee>
<id>1</id>
<name>xxx</name>
<marks>45</marks>
<class>7</class>
</Employee>'

select x.value('local-name(.)','varchar(50)) as attributename,
x.value('.','varchar(50)') as value
from @xml.nodes('/*/*') n(x)



Thanks

Jack
Go to Top of Page
   

- Advertisement -