title: SQL Output as XML stop repeating the namespace
body: <p>I'm using SSIS\SQL Server 2014 and am using the below SQL statement to output to XML. </p>
  
  <p>In summary, 1 property can have many schedules.  I only want the name space to appear once before the 'Job' XML path, however, if there are multiple schedules, then the namespace is also appearing in the xml output for each schedule - how do I stop this?</p>
  
  <p>My code:</p>
  
  <pre><code>DECLARE @XMLOutput XML
  DECLARE @XMLOutputChar nvarchar(max)
  
  ;WITH XMLNAMESPACES('http://www.example.com' as ns)
  
  SELECT @XMLOutput =
  (
  SELECT  
  ISNULL(T1.[PropertyID],'') as PropertyId,
  ISNULL(T1.[Desc],'') as JobDescription,
      (
          SELECT
          ScheduleId as ScheduleId,
          LocationID as LocationId,
          FROM [JobSchedules]
          WHERE T1.JobIdentity = JobIdentity 
          FOR XML PATH('JobSchedules'), TYPE
      )
  FROM   [JobFile] T1 
  
  
  FOR XML PATH('Job'),TYPE,ROOT('JobLoader')
  )
  
  SET @XMLOutputChar = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;' + CONVERT(nvarchar(max),@XMLOutput)
  
  SELECT @XMLOutputChar AS XMLOutput
  </code></pre>
  
  <p>This is the desired output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;JobLoader xmlns="http://www.example.com/" &gt;
  &lt;Job&gt;
  &lt;PropertyId&gt;PROPERTYID&lt;/PropertyId&gt;
  &lt;JobDescription&gt;JOBDESCRIPTION&lt;/JobDescription&gt;
  &lt;JobSchedules&gt;
  &lt;JobSchedule&gt;
  &lt;ScheduleId&gt;SCHEDULEID&lt;/ScheduleId&gt;
  &lt;LocationId&gt;LOCATIONID&lt;/LocationId&gt;
  &lt;/JobSchedule&gt;
  &lt;/JobSchedules&gt;
  &lt;/Job&gt;
  &lt;/JobLoader&gt;
  </code></pre>
  
  <p>What am I missing?</p>