XML : Convert XML from one format to another

I have this below xml data which is stored in a table.

The XML Structure I have

  <Response>      <Question ID="1">          <Value ID="1">I want a completely natural childbirth - no medical interventions for me</Value>          <Value ID="2">no medical interventions for me</Value>      </Question>  </Response>    

I need to convert this XML to a slightly different format, like the below one.

The XML Structure I need

  <Response>      <Question ID="1">          <SelectedChoices>              <Choice>                  <ID>1</ID>              </Choice>              <Choice>                  <ID>2</ID>              </Choice>          </SelectedChoices>      </Question>  </Response>    

Here the "Value" is changed to "Choice" and "ID" attribute of "Value" element is changed to an element.

I know this can be done in other ways, like using an XSLT. But it will be much more helpful if can accomplish with SQL itself.

Can someone help me to convert this using SQL?

No comments:

Post a Comment