1

I've been tasked with taking a sample of survey results that are stored in CSV and to convert them to XML.

CSV Data

I'm still fairly new to XML, but have come up with a couple of layouts I could use and was hoping I could get some advice on what way is best to go.

1)

<survey>
    <response>
        <id>1</id>
        <question>
            <title>When did you start playing Pokemon Go?</title>
            <answer>June</answer>
        </question>
        <question>
            <title>What type of phone/OS do you play on?</title>
            <answer>Android</answer>
        </question>
        <question>
            <title>What team are you on?</title>
            <answer>Mystic (Blue)</answer>
        </question>
        <question>
            <title>What Level Are You?</title>
            <answer>29</answer>
        </question>
        <question>
            <title>How many pokemon have you caught?</title>
            <answer>0 to 1000</answer>
        </question>
        <question>
            <title>How many KM have you traveled? (Jogger medal)</title>
            <answer>Bronze</answer>
        </question>
    </response>
    ... more responses ...
</survey>

2)

<survey>
    <response id="1">
        <answer question="1">June</answer>
        <answer question="2">Android</answer>
        <answer question="3">Mystic (Blue)</answer>
        <answer question="4">29</answer>
        <answer question="5">0 to 1000</answer>
        <answer question="6">Bronze</answer>
    </response>
    ... more responses ...
</survey>

Should I include the question text at all, since it will be repeated for every response?

I will be using a XSD file to put restrictions on what the answers can be and then transforming it using an XSLT to display the data in charts/tables.

d219
  • 140
screencut
  • 43
  • 5

1 Answers1

4

Which is the better encoding really depends on what you're trying to store. If you're storing the data gathered by the survey, it'll be much different than if you're storing a record of the user input from the survey.


If you're storing the record of user input, something like this may be appropriate:

<survey>
  <questions>
    <question id="1">When did you start playing Pokemon Go?</question>
    <question id="2">What type of phone/OS do you play on?</question>
    <question id="3">What team are you on?</question>
    <question id="4">What Level Are You?</question>
    <question id="5">How many pokemon have you caught?</question>
    <question id="6">How many KM have you traveled? (Jogger medal)</question>
  </questions>
  <responses>
    <response id="1">
        <answer question="1">June</answer>
        <answer question="2">Android</answer>
        <answer question="3">Mystic (Blue)</answer>
        <answer question="4">29</answer>
        <answer question="5">0 to 1000</answer>
        <answer question="6">Bronze</answer>
    </response>
    ... more responses ...
  </responses>
</survey>

The important thing here is to include enough information to reconstruct the survey. If the answers aren't free-form, it might be worth including the available responses in the question block, possibly like this:

<survey>
  <questions>
    ...
    <question id="2" text="What type of phone/OS do you play on?">
      <option id="1">iOS</option>   
      <option id="2">Android</option>
      <option id="3">Other</option>
    </question>
    ...
  </questions>
  <responses>
    <response id="1">
        ...
        <answer question="2" response="1"/>
        ...
    </response>
    <response id="2">
        ...
        <answer question="2" response="3">MS Surface</answer>
        ...
    </response>
    ... more responses ...
  </responses>
</survey>

If you're just storing the collected data, it can be much simpler (basically just providing by name access to the fields):

<player-data>
  <player id="1"
          started="June"
          platform="Android"
          team="Mystic (Blue)"
          level="29"
          catchCount="0 to 1000"
          joggerMedal="Bronze"/>
  ... more players ...
</player-data>
Morgen
  • 1,081