The previous answer
select 'hello' as [@attr1], 'world' for xml path('mynode')
only works because 'world' is a constant one-row result. It will stop working as you wish if you need multiple rows like in
select 'hello' as [@attr1], world
from
(select 'world1' AS world
union
select 'world2') temp
for xml path('mynode')
because it will give you the unwanted result
<mynode attr1="hello">
<world>world1</world>
</mynode>
<mynode attr1="hello">
<world>world2</world>
</mynode>
So, if you are after the result
<mynode attr1="hello">world1</mynode>
<mynode attr1="hello">world2</mynode>
you have to use
select 'hello' as [mynode/@attr1], world as mynode
(select 'world1' AS world
union
select 'world2') temp
for xml path('')