Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server.
Browse by Tags · View All
XML 112
TSQL 69
XQuery 69
XQuery Functions 67
XQuery Training 65
XQuery in TSQL 64
XQuery Tutorial 63
SQL Server XQuery 63
XQuery-Labs 57
BRH 38

Archive · View All
September 2008 32
August 2008 30
July 2008 21
August 2009 19
June 2009 19
May 2010 18
January 2009 15
January 2010 14
October 2008 14
June 2008 13

XQuery Lab 34 - How to retrieve the child element at a specified position?

Sep 14 2008 6:42PM by Jacob Sebastian   

 

Some times you might need to retrieve the XML element at a given position. It may be because you are running a loop over all the elements of the XML document to perform some application specific operations or you want to pass those elements to another application/stored-procedure/function etc to perform some custom processing. It could also be that you need to access each element individually and do some actions.

The following example demonstrates how to retrieve the child element of an XML document, at the specified position.

-- XML instance
DECLARE @x1 XML
SELECT @x1 = '
<Employees Dept="IT">
<Employee Number="1001" Name="Jacob"/>
<Employee Number="1002" Name="Bob" ReportsTo="Steve"/>
</Employees>'


SELECT
@x1.query('/Employees/Employee[1]')

/*
OUTPUT:
<Employee Number="1001" Name="Jacob" />
*/

SELECT
@x1.query('/Employees/Employee[2]')

/*
OUTPUT:
<Employee Number="1002" Name="Bob" ReportsTo="Steve" />
*/

The following example shows how to use a variable to specify the position of the element needed.

-- XML instance
DECLARE @x1 XML
SELECT @x1 = '
<Employees Dept="IT">
<Employee Number="1001" Name="Jacob"/>
<Employee Number="1002" Name="Bob" ReportsTo="Steve"/>
</Employees>'


DECLARE @i INT
SELECT @i = 2

SELECT
@x1.query('/Employees/Employee[sql:variable("@i")]')

/*
OUTPUT:
<Employee Number="1002" Name="Bob" ReportsTo="Steve" />
*/

SELECT
@x1.query('/Employees/Employee[position()=sql:variable("@i")]')
/*
OUTPUT:
<Employee Number="1002" Name="Bob" ReportsTo="Steve" />
*/

XQuery Labs - A Collection of XQuery Sample Scripts and Tutorials

Tags: XQuery-Labs, XML, XQuery, XQuery Functions, SQL Server XQuery, XQuery in TSQL, XQuery Training, XQuery Tutorial,


Jacob Sebastian
1 · 100% · 32004
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]