Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 XML data type & namespace problem

Author  Topic 

macon
Starting Member

1 Post

Posted - 2008-03-12 : 11:58:41
I have a problem with adding a namespace declaration to my XML query. As soon as I add the namespace declaration to the final XQuery most of my nodes disappear from the document. I've got a simplified version of it here so people can run it.

If I remove the declare clause (in red) it works and you see all the nodes but then I don't have the namespace. So it seems to be that the subquery (in {}) isn't recognising the namespace declaration?



declare @Tmp table (nodeValue int)
insert into @Tmp (nodeValue) values (1)
insert into @Tmp (nodeValue) values (2)
insert into @Tmp (nodeValue) values (3)

declare @x xml
set @x = (
select
nodeValue
from @Tmp
for xml path('node'), root('root'), type
)

select @x.query('declare default element namespace "http://www.eqos.com/collaborator/data/";
<someOtherRoot>
{
for $node in /root/node
return
<proj class="something" key="{ data($node/nodeValue) }" />
}
</someOtherRoot>
')
   

- Advertisement -