<!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.1597" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>I was doing something similar to the PHP suggestion,
but not getting anything. Using Thomas' code, I was able to see that the data is
getting to PHP, but since it is sent by the POST method, PHP is expecting
name/value pairs, separated by ampersands. I struggled for a while in that
PHP was returning only part of the string that was sent to it by Xerte, and
realized it was breaking at an equal sign. I was using:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>myId = 5;</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>myXML = "<query>SELECT * FROM tablename WHERE id
= " + myId + " ORDER BY fname</query>";</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>myReq = new XML(myXML);</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>xmlPage.sendAndLoad(myReq,
'http://localhost/test/test_xerte.php');</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>... and was receiving back only "5 ORDER BY fname". I
eventually realized that the string I was getting back was everything after the
equal sign. So I amended my string to:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>myXML = "type=SELECT&table=tablename&id=" +
myId + "&sort=fname";</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>... and now I can see all of the name/value pairs in
PHP and echo them back. I found that I needed to urlencode the strings in PHP
before echoing them, and then unescape the returning string in
Xerte.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>My PHP code is now:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007><?php # test_xerte.php</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=984444417-29082007>// this
script is a test of whether I can connect to a php script through
Xerte.</SPAN></FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>if (!empty ($_POST)) {<BR> echo
"<reply>";<BR> foreach ($_POST as $key => $value)
{<BR> echo
urlencode ("<$key>$value</$key>\n");<BR>
}<BR> echo "</reply>";<BR>} else {<BR>
echo '<reply>The $_POST array was
empty.</reply>';<BR>}</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>?> </SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>In Xerte, the script that receives that data back from
PHP is:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>xmlResponse =
unescape(xmlPage.templateData.reply);</SPAN></FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" size=2><SPAN
class=984444417-29082007>replyPage.myText = '<p><b>Response from
script: </b>';<BR>replyPage.myText += '<i>' + xmlResponse +
'</i></p>';<BR>replyPage.myText += "<br /><p>That's all
folks!</p><br /><p>Another
paragraph.</p>";</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>So now I see all of the values returned by PHP. The xml
tags don't display, of course, but I should be able to figure out how to work
with them.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>But since you mentioned implementing loadVars, I would
like to say that it seems that would be an easier way to communicate with PHP
than using XML. It would be similar to how PHP scripts communicate with one
another, and would make database communication easier to implement, since you
wouldn't have to convert back and forth between name/value style and xml
style.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=984444417-29082007>- Paul</SPAN></FONT></DIV><FONT face="Courier New"
size=2></FONT><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>Tenney
Julian<BR><B>Sent:</B> Wednesday, August 29, 2007 5:22 AM<BR><B>To:</B> Xerte
discussion list<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=365101312-29082007><FONT face=Verdana
color=#0000ff size=2>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=365101312-29082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=365101312-29082007><FONT face=Verdana
color=#0000ff size=2>Xerte does do the sendAndLoad a little differently as in
Xerte sendAndLoad is a method of an icon; in Flash it is a method of an xml
object. I did it this way because you need to listen for the event and it is
easy to set up listeners to events broadcast by icons in Xerte, rather than
objects. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=365101312-29082007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=365101312-29082007><FONT face=Verdana
color=#0000ff size=2>I can implement a loadVars in similar fasion if you
want?</FONT></SPAN></DIV>
<DIV><SPAN class=365101312-29082007><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=365101312-29082007><FONT face=Verdana color=#0000ff size=2>To
get at the string POSTed into the php page, try this:</FONT></SPAN></DIV>
<DIV><SPAN class=365101312-29082007><FONT color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=365101312-29082007>
<P><FONT face=Verdana color=#0000ff size=2>$empty = $post =
array();</FONT></P>
<P><FONT face=Verdana color=#0000ff size=2>foreach ($_POST as $varname =>
$varvalue) {<BR></FONT><FONT color=#0000ff><FONT face=Verdana><FONT
size=2><SPAN class=365101312-29082007> </SPAN>if (empty($varvalue))
{<BR><SPAN class=365101312-29082007> </SPAN>$empty[$varname]
= $varvalue;<BR><SPAN class=365101312-29082007> }</SPAN> else
{<BR><SPAN class=365101312-29082007> </SPAN>$post[$varname]
= $varvalue;<BR><SPAN class=365101312-29082007>
</SPAN>}<BR></FONT></FONT><FONT face=Verdana size=2>}</FONT></FONT></P>
<P><SPAN class=365101312-29082007><FONT face=Verdana color=#0000ff
size=2>[Thanks to Thomas]</FONT></SPAN></P>
<P><SPAN class=365101312-29082007><FONT face=Verdana color=#0000ff
size=2>Julian</FONT></SPAN></SPAN></P></DIV></BLOCKQUOTE></BODY></HTML>