<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Having trouble reading XML from an external script</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16525" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>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 </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2><A
href="http://www.nottingham.ac.uk/xerte/examples/loadXML.zip">www.nottingham.ac.uk/xerte/examples/loadXML.zip</A></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- Create a new file</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- Give the first page the id 'xmlPage'</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- add a script to it:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>myReq = new
XML('<request/>');<BR>xmlPage.sendAndLoad(myReq, FileLocation +
'data.xml');</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- Add an interaction ot the page</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- Add an event response to the interaction: eventName:
'onSendAndLoad', icon: 'xmlPage'</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>- Add a script icon to the event
response:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff
size=2>debug(xmlPage.serverXML);<BR>debug(xmlPage.templateData.data);</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>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:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2><question></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> <prompt>Here is a
prompt</prompt></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> <option></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>
<text>True</text></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> <feedback>You clicked option
true</feedback></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> </option></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> <option></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>
<text>false</text></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2> <feedback>You clicked option
false</feedback></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>
</option></FONT></SPAN></DIV></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></question></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>You access the values of the nodes and attributes
using</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>iconID.templateData.question[0].prompt[0]; //returns 'here
is a prompt'</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>or </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>iconID.templateData.option[1].text[0]; //returns
'true'</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>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.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2>Julian</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=356582208-28082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV><BR>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk
[mailto:xerte-bounces@lists.nottingham.ac.uk] <B>On Behalf Of
</B>xerte@lists.nottingham.ac.uk<BR><B>Sent:</B> 24 August 2007
17:41<BR><B>To:</B> xerte@lists.nottingham.ac.uk<BR><B>Subject:</B> [Xerte]
Having trouble reading XML from an external script<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P><FONT face=Arial size=2>Using Xerte 1.7</FONT> </P>
<P><FONT face=Arial size=2>I am attempting to display some XML returned from
an external PHP script, and not having any success. Here is my script icon
contents:</FONT></P>
<P><FONT face=Arial size=2>========</FONT> <BR><FONT face=Arial size=2>var
xml_msg:String = "<params fname=\"Fred\" lname=\"Smith\" />";</FONT>
<BR><FONT face=Arial size=2>var my_xml:XML = new XML(xml_msg);</FONT>
<BR><FONT face=Arial size=2>var myReply:XML = new XML();</FONT> <BR><FONT
face=Arial size=2>//reply.myText = "Supposed to be the reply from my PHP
script";</FONT> <BR><FONT face=Arial size=2>//myReply.ignorewhite =
true;</FONT> </P>
<P><FONT face=Arial size=2>my_xml.sendAndLoad('<A
href="http://localhost/test/test_xerte.php'">http://localhost/test/test_xerte.php'</A>,
myReply);</FONT> </P>
<P><FONT face=Arial size=2>reply.myText =
myReply.firstChild.attributes.value;</FONT> <BR><FONT face=Arial
size=2>=========</FONT> </P>
<P><FONT face=Arial size=2>My PHP script isn't doing anything with the data
sent to it, it just returns some XML:</FONT> </P>
<P><FONT face=Arial size=2>=========</FONT> <BR><FONT face=Arial
size=2><?php # test_xerte.php</FONT> </P>
<P><FONT face=Arial size=2>// this script is a test of whether I can connect
to a php script through Xerte.</FONT> </P>
<P><FONT face=Arial size=2>echo '<?xml version="1.0" ?></FONT> <BR><FONT
face=Arial size=2> <reply value="Hello, World!"
/>';</FONT> <BR><FONT face=Arial size=2>?> </FONT><BR><FONT face=Arial
size=2>=========</FONT> </P>
<P><FONT face=Arial size=2>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.</FONT></P>
<P><FONT face=Arial size=2>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.</FONT></P>
<P><FONT face=Arial size=2>Any suggestions are greatly appreciated.</FONT>
</P><BR><BR>
<P><FONT face="Courier New" color=#808080
size=2>_____________________________</FONT> </P>
<P><FONT face="Courier New" color=#808080 size=2><B> Paul
Swanson</B></FONT> <BR><FONT face="Courier New" color=#808080
size=2> Instructional Designer</FONT> <BR><FONT face="Courier New"
color=#808080 size=2> Harland Financial Solutions</FONT> <BR><FONT
face="Courier New" color=#808080 size=2>_____________________________</FONT>
</P></BLOCKQUOTE></BODY></HTML>