I didn't quite follow what you meant by "core of the xml" and "dynamic way". You may already be doing what I am describing below - if you are looking for a more automated way, you could try raw or auto directives, but then you will have much less flexibility.Step 1. Write the query to select all the columns you want joining the tables you need etc. For example:select EmployeeId, EmployeeName, Title, NodeLevel from #tmpEmployees
2. Add the xml path clause as inselect EmployeeId, EmployeeName, Title, NodeLevel from #tmpEmployees for xml path('Employee'), Root('Employees');3. Click the xml results in the grid view and while in the xml window that comes up, use XML -> Create XML Schema from the menu bar.4. Doing this will give you the xsd, but it will dump all the elements in a single level. If you need to nest the elements, use attributes etc., you can nest the selects, in the query, for example like this:create table #tmpEmployees(EmployeeId int, EmployeeName varchar(255), Title varchar(255), NodeLevel int);insert into #tmpEmployees values(1,'Sunita Beck', 'President and CEO', 1);insert into #tmpEmployees values (2,'Yosiaz', 'CFO', 2);select EmployeeId as [@IDAttribute], ( select EmployeeId, EmployeeName for xml path(''), type ) as EmployeeBasicInfo, ( select Title, NodeLevel for xml path(''), type ) as EmployeeOrgChartInfofrom #tmpEmployeesfor xml path('Employee'), Root('Employees'); drop table #tmpEmployees;Like I said earlier, you may be doing all these already. If you are, ignore this posting - I don't know a more automated way. Regardless, I hope you didn't mind that I made myself the CEO and made you report to me in my sample data *grin*