[Xerte] Having trouble reading XML from an external script

xerte at lists.nottingham.ac.uk xerte at lists.nottingham.ac.uk
Tue Aug 28 09:38:12 BST 2007

Close. Loading XML is asynchronous, so the call to load it isn't
returned straight away. You need to wait for it. I've put a simple
example at 
- Create a new file
- Give the first page the id 'xmlPage'
- add a script to it:
myReq = new XML('<request/>');
xmlPage.sendAndLoad(myReq, FileLocation + 'data.xml');
- Add an interaction ot the page
- Add an event response to the interaction: eventName: 'onSendAndLoad',
icon: 'xmlPage'
- Add a script icon to the event response:
The first object you can use is the raw xml. Do what you lkike with it.
To save a lot of processing the xml, it is also available as an object.
This object follows the structure of the xml file, but you can drill
down through the hierarchy using dot notation. So, if you have an xml
file like this:
  <prompt>Here is a prompt</prompt>
    <feedback>You clicked option true</feedback>
    <feedback>You clicked option false</feedback>
You access the values of the nodes and attributes using
iconID.templateData.question[0].prompt[0]; //returns 'here is a prompt'
iconID.templateData.option[1].text[0]; //returns 'true'
You can also construct the flowline based on the contents of the xml
file using the iconID.duplicate function. This means you can easily
create dynamic templates that build themselves at runtime using the
contents of the xml. This is a powerful approach and I use it all the
time. I'm going to document this more fully / write a manual, as it is
fairly advanced, both conceptually and technically.


	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of
xerte at lists.nottingham.ac.uk
	Sent: 24 August 2007 17:41
	To: xerte at lists.nottingham.ac.uk
	Subject: [Xerte] Having trouble reading XML from an external

	Using Xerte 1.7 

	I am attempting to display some XML returned from an external
PHP script, and not having any success. Here is my script icon contents:

	var xml_msg:String = "<params fname=\"Fred\" lname=\"Smith\"
	var my_xml:XML = new XML(xml_msg); 
	var myReply:XML = new XML(); 
	//reply.myText = "Supposed to be the reply from my PHP script"; 
	//myReply.ignorewhite = true; 


	reply.myText = myReply.firstChild.attributes.value; 

	My PHP script isn't doing anything with the data sent to it, it
just returns some XML: 

	<?php  # test_xerte.php 

	// this script is a test of whether I can connect to a php
script through Xerte. 

	echo '<?xml version="1.0" ?> 
	    <reply value="Hello, World!" />'; 

	I've also tried it without the '<?xml version="1.0" ?>'
declaration in my PHP script. In Xerte, I have a Text Display icon
(id=reply) with {myText} embedded. It displays "undefined" with the
above code. If I comment out the last two lines in the Xerte script
icon, and uncomment the reply.myText = "Supposed to be the reply from my
PHP script" that is what prints in Xerte.

	I also get "undefined" if I paste '<reply value="Hello, World!"
/>' into var myReply:XML = new XML('<reply value="Hello, World!" />')
and comment out the sendAndLoad line, so I have a feeling this problem
has nothing to do with the PHP script.

	Any suggestions are greatly appreciated. 


	 Paul Swanson 
	 Instructional Designer 
	 Harland Financial Solutions 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20070828/2bb66cd4/attachment.html

More information about the Xerte mailing list