[Xerte] Having problems duplicating nodes

Julian Tenney Julian.Tenney at nottingham.ac.uk
Tue Dec 9 09:38:46 GMT 2008


I'd use decision icons, set to randomUnused to present the questions -
then there's no need to randomise your arrays. Pick out each question
using icon.parentNode.index() or similar, with a page on the deision for
each question - but you'll make those with duplicate().  You will still
need to build some arrays for sec1Questions, sec2Questions though. I
might be tempted to make those arrays of xmlNodes rather than the bits
of templateData. You can get the pre-XML2Object xml from your file with
the variable extXML. I'd loop over that, picking out your nodes and
adding them to your arrays, then use those arrays to drive your code.

 

HTH?

 

J

 

From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Julian Tenney
Sent: Monday, December 08, 2008 10:52 PM
To: Xerte discussion list
Subject: RE: [Xerte] Having problems duplicating nodes

 

how fussy are you about the .xml format?

 

could you work with:

 

<questions>

 

  <question section="1">

    <!--data for question here -->

  </question>

 

  <!--etc-->

 

</questions>

 

and generally, what does the .rlo need to do? Present a framework of
content for each section, and then show the quiz (on the last page?). Do
the page types vary?

 

and then a final section framework summarises and then shows all
questions, randomised?

 

 

 

________________________________

From: xerte-bounces at lists.nottingham.ac.uk on behalf of Paul Swanson
Sent: Mon 08/12/2008 19:15
To: Xerte discussion list
Subject: RE: [Xerte] Having problems duplicating nodes

Commenting out the two randomQuizData lines doesn't change anything.
I've moved the statement that randomizes the questions to the button
that launches the final test, rather than have it in the setup script.

 

Maybe I'm just going about this entirely the wrong way. What I want to
accomplish is to have all my test questions within one setup.xml file. I
have six lessons, and some of the questions will also be presented at
the end of each lesson. So I need to parse which questions are for
lesson 1, which are for lesson 2, etc. Once the student has completed
all of the lessons, they must take a test to pass the course. This test
will be comprised of all of the questions for all of the lessons, with
the questions randomized. Am I on the right track with what I've been
trying to do, or do I need to take a different approach?

 

Paul

	 

	
________________________________


	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Julian Tenney
	Sent: Thursday, December 04, 2008 11:32 PM
	To: Xerte discussion list
	Subject: RE: [Xerte] Having problems duplicating nodes

	You are creating references to the same array.

	 

	quizData = templateData.quiz[0]; // non-randomized questions

	 

	randomQuizData = templateData.quiz[0]; // for randomized
questions
	randomQuizData.question.randomize(); // randomize the list of
questions.

	 

	quizData.question is also randomised.

	 

________________________________

	From: xerte-bounces at lists.nottingham.ac.uk on behalf of Paul
Swanson
	Sent: Thu 04/12/2008 19:32
	To: Xerte discussion list
	Subject: RE: [Xerte] Having problems duplicating nodes

	I think the problem is where I take the quiz part of
templateData and assign it to quizData:

	 

	quizData = templateData.quiz[0]; // non-randomized questions

	 

	randomQuizData = templateData.quiz[0]; // for randomized
questions
	randomQuizData.question.randomize(); // randomize the list of
questions.

	All of the questions are between the <quiz> </quiz> tags, and
there is only one set of those. To indicate which lesson the question is
for, I have an attribute for the <question> tag (lesson="1", lesson="2",
etc.). Then I try to get just the lesson 1 questions with:

	 

	// create arrays for lesson 1 quiz
	lesson1quiz = new Array ();
	wrapupQbuilt = new Array (); // for questions
	wrapupBuilt = new Array (); // for question answers
	wrapupTracking = new Array ();
	wrapupAnswers = new Array ();

	 

	lesson1Counter = 0; // counter for number of questions

	 

	// loop through all questions to get lesson 1
	for (i = 0; i < quizData.question.length; i++) {

	 

	  if (quizData.question[i].lesson == '1') {
	  
	    lesson1quiz[lesson1Counter].question = quizData.question[i];
	    lesson1Counter++;

	 

	  } // end of quizData.question[i] conditional

	 

	  myCounter = i + 1;

	 

	} // end of for loop

	 

	// create the right number of questions
	if (wrapupQbuilt[lesson1Counter] != 'true') {
	
icon.nextSibling.childNodes[6].childNodes[0].childNodes[2].childNodes[0]
.childNodes[1].duplicate(lesson1Counter-1);
	}
	wrapupQbuilt[lesson1Counter] = 'true';

	 

	But when I print lesson1quiz.length for debugging purposes, it
prints 0, I was expecting it to print 2. Yet if I hard code the index of
the lesson1quiz to get a question, it does appear. Hard code 0 and it
pulls the second question, hard code 1 and it prints the first question
(backwards from what I expected, but the order isn't important), so
there must be something in the lesson1quiz array.

	 

	Paul

	 

		 

		
________________________________


		From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Julian Tenney
		Sent: Thursday, December 04, 2008 12:58 AM
		To: Xerte discussion list
		Subject: RE: [Xerte] Having problems duplicating nodes

		What you describe sounds right. I think the index is
correct (and that' backed up by the fact you use the same var to display
the current page number to the user).

		 

		So if that is indeed correct, then it must be an issue
with reading the data out of the xml data. Are you using th index in the
right part of the templateData path?

		 

		From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
		Sent: Wednesday, December 03, 2008 10:04 PM
		To: Xerte discussion list
		Subject: RE: [Xerte] Having problems duplicating nodes

		 

		Well, apparently I was. I had the duplicate code in the
entry frame of lesson 1, so I guess it was executing each time I moved
from page to page in lesson 1? I moved the code to just above the
interface icon (so it can only run once), made the necessary changes to
the childNodes structure, and it was still acting funny. I then found
that I had both a variable and an icon id of 'lesson1Counter' so it's no
wonder it was acting inconsistently. ;o)  I fixed that and now I'm
consistently getting the correct number of question nodes.

		 

		I still have one problem though: it only displays one
question. When I get to the first question node, it displays the
question correctly, the second node displays the same question, and if I
back up to the first question node, it's blank.  Here is the code where
I get the question number:

		 

		questIndex = icon.parentNode.index() - 1;

		 

		The script icon with this code is the first icon in the
proto Wrap Up page (what I was calling the question node above), and the
proto Wrap Up page is the second child of the wrap up framework (the
Entry Frame being the first child), so questIndex should be 0 for the
first question, and 1 for the next, right? I'm using questIndex+1 for a
page counter, and that is correctly displaying 1 for question 1 and 2
for question 2, but the questions don't change. Any insight on that?

		 

		Thanks for all your help!

		 

		P

			 

			
________________________________


			From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Julian Tenney
			Sent: Wednesday, December 03, 2008 12:45 PM
			To: Xerte discussion list
			Subject: RE: [Xerte] Having problems duplicating
nodes

			You're not duplicating icons more than once are
you? When you call duplicate, you are manipulatingthe xml in the rlo
file:

			 

			//this makes n + 1 children on icon.nextSibling:

			icon.nextSibling.firstChild.duplicate(n);

			 

			//call it again (perhaps because we revisit this
page):

			icon.nextSibling.firstChild.duplicate(n);

			 

			//how many children?

			debug(icon.nextSibling.childNodes.length);
//duh. Twice as many as I needed.

			 

			//so, only let the duplicate run once, 'cos if
we revisit a page, we'll end up with too many xml nodes...

			if (someFlag != true){

			  duplicate(....make icons here...);

			  someFlag = true;

			}

			 

			//i tend to do it like this, so duplicate code
in icon will only ever run once:

			if (icon.attributes.built != 'true'){

			  //duplicate and other logic here

			  icon.attributes.built = 'true';

			}

			 

			sort that out and the see if you've got any
issues left. The thing is that 'icon' refers to the underlying xml node
- that is key to understanding what's happening with duplicate(); make
sure the code that builds the piece only runs once.

			 

			J

			 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20081209/33594a5f/attachment.html


More information about the Xerte mailing list