I have a parent child relationship set up in a table in an SQL server table (ie each row has an ID and a parentID, parentID is null for top level). There is no limit on the number of levels deep that the relationship can go.

I am trying to display this in a treeview webcontrol, and want to create a stored procedure that will output a hierachical representation of the relationship in XML format (which I can then bind to the treeview control).

I have managed to get a single parent/child level to output correctly using the FOR XML EXPLICIT command, but I don't know how to output it to an indefinite number of levels.

Any help on this would be very much appreciated.

Thanks in advance!