TSQL for xml add schema attribute to root node

kondronaute

New Member
My situation is this (simplified):\[code\]DECLARE @period XML = (SELECT'2012' 'period'FOR XML PATH(''), ROOT ('survey'))DECLARE @persons XML = (SELECTPerson.Name 'users/person'FROM PersonFOR XML PATH(''), ROOT ('company'))SET @persons.modify('insert sql:variable("@period") as first into (/company)[1]')SELECT @persons\[/code\]Which gives me a XML like this:\[code\]<company> <survey> <period>2012</period> </survey> <users> <person>Dubach</person> </users> <users> <person>Pletscher</person> </users> ...\[/code\]Now I need to add a XML-schema to the root node like this:\[code\]<company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mydomain.com/xmlns/bla/blabla/myschema.xsd" xmlns="http://www.mydomain.com/xmlns/bla/blabla"> <survey> <period>2012</period> </survey> <users> <person>Dubach</person> </users> <users> <person>Pletscher</person> </users> ...\[/code\]Microsoft says I have to use WITH XMLNAMESPACES before the SELECT statement but that does not work in my case.How can I add these xmlnamespaces?
 
Back
Top