Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper XML structure for a Questionnaire?

Status
Not open for further replies.

lito247

Programmer
May 21, 2004
10
US
Hello,
I'm probably over thinking this, but I don't know of a proper way of building the schema for a questionnaire, specifically when I have a list of questions that depend on a YES or NO answer...

For example:
Do you own a car? (Y|N)
If yes, what is the Brand and Model?
If yes, what Color is it?

Do you plan to buy a car? (Y|N)
If yes, how much are you willing to spend?
If yes, when are you planning to buy?

My confusion is whether or not those "dependent" questions/answers need to live as child nodes inside the top question. If there are no rules regarding this, what is the best practice? An example would be helpful.

Thank you.
 
There are no "rules" to building XML, its all about semantics. What makes logical sense? There's more than one way, and it depends on your personal preference.

Personally, I would do something like this:
Code:
<questionnaire>
  <question>
    <text>Do you own a car?</text>
    <answer>
      <value>Y</value>
      <question>
        <text>What is the Brand and Model?</text>
      </question>
      <question>
        <text>What Color is it?</text>
      </question>
    </answer>
    <answer>
      <value>N</value>
    </answer>
  </question>
  <question>
    <text>Do you plan to buy a car? </text>
    <answer>
      <value>Y</value>
      <question>
        <text>How much are you willing to spend?</text>
      </question>
      <question>
        <text>When are you planning to buy?</text>
      </question>
    </answer>
    <answer>
      <value>N</value>
    </answer>
  </question>
</questionnaire>
The structure will depend on what semantic information it needs to encapture and how that information is to be used.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top