Showing posts with label specval. Show all posts
Showing posts with label specval. Show all posts

Friday, March 30, 2012

Return attributes from all child nodes

Ok this is the last step I hope. Trying to return a table based on
this XML:
<PARENT>
<ITEM spec="spec1 specval="red" /ITEM>
<ITEM spec="spec2 specval="white" /ITEM>
<ITEM spec="spec3 specval="blue" /ITEM>
</PARENT>
I need to return a table:
SPEC SPECVAL
spec1 red
spec2 white
spec3 blue
Thanks for any help on this.
-RichardHow about something like this?
DECLARE @.selxml xml
SET @.selxml ='
<PARENT>
<ITEM spec="spec1" specval="red" />
<ITEM spec="spec2" specval="white" />
<ITEM spec="spec3" specval="blue" />
</PARENT>'
SELECT x.value('data(./@.spec)', 'nvarchar(MAX)') as SPEC,
x.value('data(./@.specval)', 'nvarchar(MAX)') as SPECVAL
FROM @.selxml.nodes('/PARENT/ITEM') T(x)
Denis Ruckebusch
http://blogs.msdn.com/denisruc
--
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"sk8man31" <me@.aol.com> wrote in message
news:dqk3925c44br94nrn7m3msru3glgpq7h2c@.
4ax.com...
> Ok this is the last step I hope. Trying to return a table based on
> this XML:
> <PARENT>
> <ITEM spec="spec1 specval="red" /ITEM>
> <ITEM spec="spec2 specval="white" /ITEM>
> <ITEM spec="spec3 specval="blue" /ITEM>
> </PARENT>
> I need to return a table:
> SPEC SPECVAL
> spec1 red
> spec2 white
> spec3 blue
> Thanks for any help on this.
> -Richard