Using Asp Function GetALLXMLChart(nOrgID) Dim DataSource Dim sSQL Dim arrSupervisor Dim arrEmployee Dim iBound Dim iChildren Dim Data Dim RecNo Dim sError Dim tRStable Dim id, BookMark Dim Result Dim iColor Dim objXML Dim sXMLChart ConnectionString = GetConnectionString Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open ConnectionString sSQL = "SELECT *, " sSQL = sSQL & "(select count(" & sParentField & ") FROM " & sTableName & " as t2 where t2.[" & sParentField & "] = " sSQL = sSQL & "t1.[" & sChildField & "]) as ChildCount, " sSQL = sSQL & "(select count(" & sParentField & ") FROM " & sTableName & " as t2 where t1.[" & sParentField & "] = " sSQL = sSQL & "t2.[" & sChildField & "]) as HasParent " sSQL = sSQL & "from " & sTableName & " as t1 " Set DataSource = Conn.Execute(sSQL) If Not DataSource.EOF Then Set objXML = Server.CreateObject("MSXML2.DOMDocument") DataSource.Save objXML, adPersistXML sXMLChart = objXML.xml sXMLChart = Replace(sXMLChart, "rs:data", "RS") sXMLChart = Replace(sXMLChart, "z:row", "ROW") GetALLXMLChart = sXMLChart Set objXML = Nothing End If Set DataSource = Nothing Set Conn = Nothing End Function where: sTableName is the table or the view that you would like to extract the XML data from. sChildField is the employee ID sParentField is the manager ID