[Xerte] Can text imported from an XML file be formatted?

Tenney Julian Julian.Tenney at nottingham.ac.uk
Fri Jun 20 08:59:22 BST 2008


You can also set the properties in icons with code
 
icon.nextSibling.attributes.label = myLabel;
 
Which is sometimes more convenient, especially whenyou want to
dynamically generate ids for icons. e.g. you might be building a hot
object type interaction, and the objects are text icons duplicated based
on the xml you load. In that case you might want to also set up event
handlers for each object, so you duplicate the text icons, and then
duplicate a prototypical event handler, and you then loop over the icons
to set the id property on the text icons and the icon property on the
event handlers,

________________________________

From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
Sent: 19 June 2008 22:58
To: Xerte discussion list
Subject: RE: [Xerte] Can text imported from an XML file be formatted?


Thanks, Jules
 
I figured there must be a way. Your suggestion works great.
 
I'm basing my piece off the example you refer to, and was already
loading the XML into templateData, then grabbing the <quiz> node and
assigning it to an object called quizData. I'm accessing it with
quizData.question[0] syntax. And I'm using the duplicate() method you
describe in the example to automatically build the pages from the XML.
 
I also figured out a way to automagically prefix a letter to each
option, so the question/options look like:
 
How many beans make five?

	A) One
	B) Two
	C) ...

I did this by creating a variable to hold the ASCII character code for
A:
 
// create a variable to convert answer number to character
charCode = 65; // ASCII code for letter A
 
Then on the radio button response, I set the label property to:
{String.fromCharCode(charCode + icon.index()) + ')  ' +
quizData.question[quesIndex].answer[icon.index()]}
 
I love the power of Xerte's scripting!
 
Paul


________________________________

	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Tenney Julian
	Sent: Thursday, June 19, 2008 2:21 PM
	To: Xerte discussion list
	Subject: RE: [Xerte] Can text imported from an XML file be
formatted?
	
	
	you're on the right lines
	 
	<question><![CDATA[How <b>long</b> is a piece of
string]]></question>
	 
	will do what you need.
	 
	If you set the templateData property of the LO icon to
FileLocation + 'myXMLFile.xml', you'll get the data from the XML as an
object, which is much easier / more convenient to handle. So, your file
looks like this:
	 
	<quiz>
	  <question><![CDATA[How long is a piece of
string?]]></question>
	  <question><![CDATA[How many beans make five?]]></question>
	</quiz>
	 
	then you can access the data using:
	 
	templateData.quiz[0].question[0]; //returns 'How long is a piece
of string?'
	 
	and
	 
	templateData.quiz[0].question[1]; //returns 'How many beans make
five?'
	 
	Xerte takes care of loading the data up, and it all exists in
that object form before the piece starts to play - no need to load it or
handle any events. Your code can start to use it rightaway. Your file
will be more complex of course, but you ge the idea. It's very powerful
- look at the developing templates doc on the website for some ideas
about making your piece dynamic. Xerte really excels in this area -
because you can create icons at runtime based on the data (one of the
things I always wanted AW to be able to do). The example in the doc is a
quiz, so you'll find it useful if you haven't read it already,
	 
	J
	 

________________________________

	From: xerte-bounces at lists.nottingham.ac.uk on behalf of Paul
Swanson
	Sent: Thu 19/06/2008 19:59
	To: xerte at lists.nottingham.ac.uk
	Subject: [Xerte] Can text imported from an XML file be
formatted?
	
	

	I'm making an XML file to hold quiz information, and I wonder if
there is a way to make some words from the quiz bold or a different
color? I found that if I insert html tags, such as <b></b> within the
xml text that text is truncated at the first < when displayed in Xerte.
Would using [!CDATA[]] tags allow me to insert html tags, and if so,
how?

	My XML file has questions in the following format: 

	<question> 
	        <prompt>Which item under Policy controls access to the
simple policies in LPL?</prompt> 
	        <answer correct="false">Policy Components</answer> 
	        <answer correct="false">Standard Policies</answer> 
	        <answer correct="true">Default Policies</answer> 
	        <answer correct="false">Access Limitations</answer> 
	</question> 

	If I wanted to bold the word 'Policy' in the <prompt> node, how
would I do that? 

	_____________________________ 

	 Paul Swanson 
	 Instructional Designer 
	 Harland Financial Solutions 
	 800.274.7280 Ext. 2462 
	 Paul.Swanson at harlandfs.com 
	_____________________________ 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20080620/1a1119c5/attachment.html


More information about the Xerte mailing list