title: Transform XML into table variable
body: <p>Can anyone please show me how to turn the following XML string into a table variable with the following structure:</p>
  
  <pre><code>DECLARE @xml XML = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;skillsProfilesTargets&gt;
      &lt;skill ID="1"&gt;
          &lt;profile ID="50" targetLevel="75" /&gt;
          &lt;profile ID="60" targetLevel="75.00"/&gt;
          &lt;profile ID="70" targetLevel="60.00"/&gt;
      &lt;/skill&gt;
      &lt;skill ID="2"&gt;
          &lt;profile ID="50" targetLevel="75" /&gt;
          &lt;profile ID="60" targetLevel="50.00"/&gt;
      &lt;/skill&gt;
      &lt;skill ID="3"&gt;
          &lt;profile ID="50" targetLevel="" /&gt;
          &lt;profile ID="60" targetLevel="75"/&gt;
          &lt;profile ID="90" targetLevel="60.00"/&gt;
      &lt;/skill&gt;
      &lt;skill ID="4"&gt;
          &lt;profile ID="50" targetLevel="" /&gt;
          &lt;profile ID="60" targetLevel="75"/&gt;
          &lt;profile ID="100" targetLevel="75"/&gt;
          &lt;profile ID="250" targetLevel="100"/&gt;
      &lt;/skill&gt;
  &lt;/skillsProfilesTargets&gt;'
  
  
  SkillID profileID   targetLevel
  -----------------------------------
  1       50      75
  1       60      75
  1       70      60
  2       50      60
  2       60      50
  3       50      NULL
  3       60      75
  </code></pre>
  
  <p>I've been looking at a number of tutorials online, but they all assume each 'skill' node has the same number of child nodes.</p>
  
  <p>Thanks in advance.</p>