Can someone algorithmically explain this TSQL UDF with XML?

Can someone please provide an algorithmic description of what this TSQL UDF is doing? I am not familiar with XML for TSQL.

FUNCTION [Common].[XmlArrayOfInt]

(@Xml AS XML (Common.ArrayOfIntegersSchema))



      INSERT INTO @Result(Value)
      SELECT T.c.value('.','int') AS Value
      FROM @Xml.nodes('/ArrayOfInt/int') AS T(c)

Also are value and nodes built-in TSQL functions? And what is '/ArrayOfInt/int'?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
To start at the end: '/ArrayOfInt/int' is an xpath query with which you can select parts of an xml document. This one just selects all 'int' nodes under the root node 'ArrayOfInt' but it can contain a lot more complicated queries in itself.

Given an xml document as input, this function returns a table that contains all values in the 'int' nodes.

So given this xml document:


Open in new window

It would return:


Open in new window

Yes, @Xml.nodes and T.c.value are built-in functions to work with xml data. See for more info under the heading 'Methods on XML Data Type' at this page:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.