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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with XML Structure

Status
Not open for further replies.

ClarkePeters

IS-IT--Management
Oct 25, 2006
4
TW
I'm doing a CMS for our distance education program and haven't programmed in years. I have a very basic xml structure for the test maker/tracker module for instructors.
My current structure seems to not work well in DOM or XPath--when I do a nodeValue I get the current element text and all descendants' text as well.

I have my current structure and two options I'll list below. And I'm soliciting your personal preference between them.

Here is my basic structure as it stands now. (which will be used to generate an xforms form after some php Dom/xpath manipulation):

<test>
<instructions> Choose one.
<question> What is the capital of Detroit?
<not> New York City </not>
<not> London </not>
<answer> this is a trick question. </answer>
//... limitless choices....
</question> //...repeating structure....
</instructions> //....repeating structure...
</test> //root

I noticed most xml docs don't put text in higher level elements--is this an issue? So I thought of grouping like this.
<test>
<instruction_set>
<instructions> Choose one.</instructions>
<question_set>
<question>What is the capital of Detroit? </question>
<answer_set>
<not> New York City </not>
<not> London </not>
<answer> this is a trick question. </answer>
</answer_set> // only one set per question.
</question> // ...
</question_set> // ...
</instructions> // ...
</instruction_set> // ...
</test>

Now a simpler model, but not so true to real world grouping/levels would be:

<test>
<instruction_set>
<instructions> Choose one.</instructions>
<question>What is the capital of Detroit? </question>
<not> New York City </not>
<not> London </not>
<answer> this is a trick question. </answer>
</question>
</instructions>
</instruction_set>
// ...
</test>


I'll be transforming this to xforms for online testing. I'll also need to alter the structure on the xforms according to instructor choice... i.e. I'll need to rearrange the answers from their original order (and possibly the questions), and of course, all elements will still need to be matched with their original instuction/question set after the rearranging.

I'm not asking for anyone to go to any length for advice (i'll take what your in the mood for :) )
Just eyeball this and tell me which structure you would personally prefer.

sincerely,
clarkepeters
 
[tt]<question_set>
<question>What is the capital of Detroit? </question>
<answer grade="0"> New York City </answer>
<answer grade="0"> London </answer>
<answer grade="1"> this is a trick question. </answer>
</question>
<!-- etc each with question tag -->
</question_set>
[/tt]
The essential idea:
[1] No <instruction> choose one </instruction> is needed. Not only it will repeat itself, you may at other time consider expand the description rather than "choose one". That heading should be left to the transformation.
[2] Do not distinguish answer's tags by <not> and <answer>. Distinguish correct/admissible answer by an attribute, grade for instance.
[3] If the student is required to choose more than answer for some, and one for some other, then add an attribute to the question. Such as
[tt]<question tickcount="2">[/tt]
for student to choose two among multiple choice. The transformation read the attribute and generate the proper description "choose two" or else.
[4] If some answers are better than others, the grade attribute can be range over set, say from 0 to 5... etc.
[5] Keep the xml data-oriented, less verbose description leaving the latter to transformation.
[6] By keeping the same tag name <answer>, it would make algorithm for shuffling the order of them less awkward.

Just some random thoughts.
 
I have some mixed up in tagging. The illustrative structure is rather this.
[tt]
<question_set>
<question>
[blue]<statement>What is the capital of Detroit? </statement>[/blue]
<answer grade="0"> New York City </answer>
<answer grade="0"> London </answer>
<answer grade="1"> this is a trick question. </answer>
</question>
<!-- etc each with question tag -->
</question_set>
[/tt]
The answers can be regrouped into an <answers> tag as well for easy xpath reference as a variation.
[tt]
<question_set>
<question>
<statement>What is the capital of Detroit? </statement>
<answers>
<answer grade="0"> New York City </answer>
<answer grade="0"> London </answer>
<answer grade="1"> this is a trick question. </answer>
</answers>
</question>
<!-- etc each with question tag -->
</question_set>
[/tt]
 
That's great, I had some of the same ideas, especially about the attributes but that's always tough trying to decide where to make an element or attribute to control data. I like your reasoning.

One question, though. I want to allow my instructors to use their own wording for the instructions. As it stands, they code their input as such:

<iii> Choose at least one of the below, be careful!
<qu> Where is Elvis?
<ans> with Waldo
<not> at Graceland
<ans> sometimes disguised as Elmo
<qu> America never really landed on the moon.
<ans>false
<not>true

notice no end tags, I do this to keep it uncluttered for the instructor and then I convert it to xml quite easily. I can convert the <not> to <answer score="0"> as you suggest at the xml level (which is a great idea). But if I leave the instructions out, then how can they access them again when they want to pull up their old tests and edit it or combine it with others to make a new test?

You've got some excellent suggestions and I know they are an improvement on my structure. I especially like the attribute suggestions and the tickcount suggestion. :)
thanks a heap.
 
Where are all the close tags for qu, ans, not ...!

I would say leave that kind of warning/description of question-set or whatever it is called to the transformation. But if you insist, I would at least put it inside a tag of its own. Mixed content model is pretty tough to transform if the document is data-oriented.
[tt]
<iii>
<general_notice> Choose at least one of the below, be careful!</general_notice>
<qu> Where is Elvis?</qu>
<!--- etc etc -->
</iii>
[/tt]
 
Thanks tsuji you've helped me out a lot ---- a whole lot. And I agree with your reasoning and will keep the instructions inside their own tag or leave it to the transformation. I'll also go with the attributes as well--great idea. I'm sure I can manage the data much better with your suggestions.

thanks again!
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top