I have a table of answers from a submission form that I need to convert to an XML file and upload to a website. Each row is one answer from one submissions and the answers need to be stored as the element name.
Table example: Note: Answer is a string value. The form has multiple questions, I'm only concerned with the Answers.
| Submission ID | Answer |
|---|---|
| 1 | foo |
| 1 | bar |
| 2 | baz |
Then the XML should like this:
<allSubmissions>
<submission>
<foo />
<bar />
</submission>
<submission>
<baz />
</submission>
</allSubmissions>
How can I accomplish this? I've been successful in using the FOR XML EXPLICIT to format tables where the column name is equal to the XML tag name, but not where the value from the column is supposed to be the name of the tag.
I would prefer NOT use some sort of concatenation work around if possible since I'd like to save the results to an XML file.
Answering the questions in the comment.
- XML is the required file type I need, so no CSV, text file, etc.
- Correction; I mispoke when I said "any string value". The answer will always be a string and it comes from a pre-defined list of about ~10 values. So I shouldn't have to worry about an illegal element name like something that starts with a number.
- The example format provided is the required schema that the validator tests against. So unfortunately, I can't do something like
<answer>foo</answer> - A text file that looks like XML would work provided that I can convert to an XML file.
foo bar(with a space) or1baz(starting with a digit), nor can they start with the lettersXMLXmlxml.<submission><id>1</id><answer>foo</answer><answer>bar</answer></submission>?