1

Topic: Parsing XML top level

Good afternoon, is on input XML

DECLARE @xml xml = ' <an ID = "1">
<b> 1 </b>
<b> 2 </b>
</a>
<an ID = "2">
<b> 3 </b>
</a>'
select
x.query ('. ')
from @xml.nodes ('//b ') t (x)
As on an output it is necessary to receive the table
b; ID
1; 1
2; 1
3; 2 

2

Re: Parsing XML top level

parent axis

3

Re: Parsing XML top level

865;

select t2.x.value (' text () [1] ', ' int ') as b, t.x.value (' @ID [1] ', ' int ') as ID
from @xml.nodes ('/a ') t (x) outer apply x.nodes (' b ') as t2 (x)