dbTalk Databases Forums  

parse xml

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss parse xml in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Anonymous
 
Posts: n/a

Default parse xml - 11-13-2009 , 11:43 PM






<SampleXML>
<Tables>
<Table value="abc" />
<Table value="123" />
</Tables>
<Fields>
<Field value="Name" />
<Field value="Price" />
</Fields>
</SampleXML>

I need to parse the above xml such that it returns the attributes in a flat
format,
e.g. abc,123
How can this be achieved using sql 2005

Reply With Quote
  #2  
Old   
Balaji
 
Posts: n/a

Default Re: parse xml - 11-16-2009 , 01:00 AM






Hi

You can use openxml function.

Regards, Balaji

"Anonymous" <Anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
SampleXML
Tables
Table value="abc" /
Table value="123" /
/Tables
Fields
Field value="Name" /
Field value="Price" /
/Fields
/SampleXML

I need to parse the above xml such that it returns the attributes in a
flat
format,
e.g. abc,123
How can this be achieved using sql 2005


Reply With Quote
  #3  
Old   
Bob
 
Posts: n/a

Default RE: parse xml - 11-16-2009 , 05:26 AM



Try this:

DECLARE @xml XML

SET @xml = '<SampleXML>
<Tables>
<Table value="abc" />
<Table value="123" />
</Tables>
<Fields>
<Field value="Name" />
<Field value="Price" />
</Fields>
</SampleXML>'


SELECT
root.x.value('(Table/@value, Field/@value)[1]', 'VARCHAR(50)') AS a,
root.x.value('(Table/@value, Field/@value)[2]', 'VARCHAR(50)') AS b
FROM @xml.nodes('SampleXML/*') root(x)



"Anonymous" wrote:

Quote:
SampleXML
Tables
Table value="abc" /
Table value="123" /
/Tables
Fields
Field value="Name" /
Field value="Price" /
/Fields
/SampleXML

I need to parse the above xml such that it returns the attributes in a flat
format,
e.g. abc,123
How can this be achieved using sql 2005


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.