Now I can control the format of the resulting XML document by using FOR XML EXPLICIT to some degree.

<project> -----first level of hierarchy(tag 1)
<form> ------ second level of hierarchy(tag 2)
<variable name=" "> ----- third level of hierarchy(tag 3)

But I want to add a node under form element, its tag name is <expression>. In the database, form, variable and expression are different tables.

In theory, expression should be in the third level of hierarchy, but I cannot assign tag 3 to two different tag name since I already assign it to variable.

And I wanted to apply schema to FOR XML EXPLICIT, then it helps generate the format that we want. But how to do that? For example, I made a schema named project_form_info.xsd.

Is there anyone who can help me with the problem? Thanks in advance!