<!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.2800.1595" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>Thanks Julian.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>I'm getting close (I think) to sorting this out. I am able
to retreive data sent from an external PHP script, but I'm having trouble
figuring out how to read what is sent to the PHP script. According to an
ActionScript 1.0 reference I found, sendAndLoad uses the POST method for sending
data, but I haven't been able to access any POST variables coming in.
Interestingly, I have a block of code in my PHP script that indicates the $_POST
array is not empty , but print_r $_POST prints nothing.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>Is there something different in Xerte's implementation of
sendAndLoad? The reference I have indicates the URL is the first argument for
the method, with the reply object 2nd, yet your example code has the reply
object first and the url second.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>Also, is there an implementation of LoadVars that could be
used? I'm more used to name/value pairs and that might be easier than using XML
format.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>My Xerte sending script:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>myId = 5;<BR>myReq = new XML();<BR>myReq.query =
"<query>SELECT * FROM tablename WHERE id = " + myId + " ORDER BY
fname</query>";<BR>xmlPage.sendAndLoad(myReq,
'http://localhost/test/test_xerte.php');</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>My PHP script:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2><?php # test_xerte.php</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>// this script is a test of whether I can connect to a php
script through Xerte.</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>ob_start();</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>if (!empty ($_POST)) {<BR> <BR>
echo "<reply>";<BR> echo "There is something coming
in:<br />";<BR> print_r ($_POST);<BR>
echo "</reply>";<BR>} else {<BR> echo '<reply>The
$_POST array was empty.</reply>';<BR>}</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>ob_end_flush();<BR>?> </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>My Xerte receiving script:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=992441520-28082007><FONT face=Arial
color=#0000ff size=2>xmlResponse =
xmlPage.templateData.reply;<BR></FONT></SPAN><SPAN
class=992441520-28082007><FONT face=Arial color=#0000ff size=2>replyPage.myText
= '<p><b>Response from script: </b>';</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2>replyPage.myText += '<i>' + xmlResponse +
'</i></p>';</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2>replyPage.myText += "<br /><p>That's all
folks!</p><br /><p>Another
paragraph.</p>";</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff size=2>This
prints:</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2><STRONG>Response from script:</STRONG> </FONT></SPAN><SPAN
class=992441520-28082007><FONT face=Arial color=#0000ff size=2><EM>There is
something coming in:</EM></FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff size=2>That's
all folks!</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2>Another paragraph.</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff size=2>I
think I just need that last bit of knowledge that allows me to parse the string
that Xerte sends to PHP.</FONT></SPAN></DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=992441520-28082007><FONT face=Arial color=#0000ff size=2>-
Paul</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; 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> Tuesday, August 28, 2007 1:38
AM<BR><B>To:</B> xerte@lists.nottingham.ac.uk<BR><B>Subject:</B> RE: [Xerte]
Having trouble reading XML from an external script<BR></FONT><BR></DIV>
<DIV></DIV>
<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></BLOCKQUOTE></BODY></HTML>