[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 
 
www.nottingham.ac.uk/xerte/examples/loadXML.zip
 
- 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:
 
debug(xmlPage.serverXML);
debug(xmlPage.templateData.data);
 
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:
 
<question>
  <prompt>Here is a prompt</prompt>
  <option>
    <text>True</text>
    <feedback>You clicked option true</feedback>
  </option>
  <option>
    <text>false</text>
    <feedback>You clicked option false</feedback>
  </option>
</question>
 
You access the values of the nodes and attributes using
 
iconID.templateData.question[0].prompt[0]; //returns 'here is a prompt'
 
or 
 
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.
 
Julian
 
 
 
 
 
 
 


________________________________

	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
script
	
	

	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; 

	my_xml.sendAndLoad('http://localhost/test/test_xerte.php',
myReply); 

	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