PDA

View Full Version : XML loading with perl


bladeMX
10-18-2002, 11:30 PM
I'm really in a rut with this, someone please help me out.

I can't seem to load XML data from a perl script back into flash.

I'm using the .sendAndLoad method with a set variable. After I get the XML data I can't seem to load it using:


userComments.sendAndLoad("http://www.mydomain.com/cgi-local/myScript.pl", replyData, "POST")

replyData = new LoadVars();

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = DisplayData;
myXML.load();


How can I load the replyData into the XML object? Is it even possible?

Here is what the XML structure from the perl script:


<?xml version="1.0" ?>
<confirmation>
<phone>5551212</phone>
<message>Hello</message>
<status>success</status>
</confirmation>


Do I need to declare the content-type from perl?

Any suggestions would help.

Thanks!

jimburton
10-18-2002, 11:38 PM
create the xml object that you want to load the reply into before calling sendandload:

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = DisplayData;

userComments.sendAndLoad("http://www.mydomain.com/cgi-local/myScript.pl", myXML)

bladeMX
10-18-2002, 11:51 PM
But after looking at it in the debugging mode, I don't see any XML data being loaded???

Here is how the code looks:


userComments = new LoadVars();
myXML = new LoadVars();
function DisplayData(success){
if (success) {
_root.gotoAndStop("output");
} else {
_root.gotoAndStop("error");
}
}

function sendComments() {
var obj = userComments;
obj.area_code1 = fromAreaCode.text;
obj.prefix1 = fromPrefix.text;
obj.suffix1 = fromSuffix.text;
obj.email_id = "me@me.com";
//obj.lang = dropDown.getValue();
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = DisplayData;
obj.text = comments.text;
userComments.sendAndLoad("http://www.mydomain.com/cgi-local/myScript.pl", myXML, "POST");
_root.gotoAndStop("wait");
}

function clearForm() {
fromAreaCode.text = ""
fromPrefix.text = ""
fromSuffix.text = ""
comments.text = ""
dropDown.setSelectedIndex(0);
}

function mainPage() {
gotoAndPlay("input");
}


Thanks for the input Jim!

jimburton
10-19-2002, 12:07 AM
LoadVars and XML are two separate types of object which you're mixing up here - they both have a sendAndLoad method but LoadVars sendAndLoad expects you to supply a LoadVars object as the target for the 'load' part of it, and XML sendAndLoad expects an XML object (one diff is that the XML.sendAndLoad method doesn't take a POST|GET method - it's always post - but you need to send both packets as xml. here is it rewritten:


myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = DisplayData;
function DisplayData(success){
if (success) {
_root.gotoAndStop("output");
} else {
_root.gotoAndStop("error");
}
}

function sendComments() {
userComments = new XML("<record><area_code1>"+fromAreaCode.text+"</area_code1>
<prefix_1>"+fromPrefix.text+"</prefix_1><suffix1>"+fromSuffix.text+
"<email_id>me@me.com</email_id><text>"+comments.text+"</text></record>");
userComments.sendAndLoad("http://www.mydomain.com/cgi-local/myScript.pl", myXML);
_root.gotoAndStop("wait");
}

function clearForm() {
fromAreaCode.text = ""
fromPrefix.text = ""
fromSuffix.text = ""
comments.text = ""
dropDown.setSelectedIndex(0);
}

function mainPage() {
gotoAndPlay("input");
}

within the function sendComments you create an xml object from scratch, send it to your perl script and load the xml that the perl gives in response into the xml object you created earlier...

bladeMX
10-19-2002, 12:19 AM
I was thinking that might be the issue, but didn't want to waste all that time I spent on myVar.sendAndLoad. :)

Now I know, never take the easy way.

Can perl handle XML? If so, how will it recognize all the variables that I will be sending?

In any case, I'm going to give that a try and let you know what happens.

Thanks for your input Jim! I appreciate it!

jimburton
10-19-2002, 12:29 AM
Can perl handle XML? - sorry, I don't know perl, but i'm sure it must be able to...myVar will be sent to the script in the http header as post data so maybe you can output some sort of debug info that tells you what post data has arrived at the script - that way you'll know how to process it. the other option is to do a loadvars at both ends, so send the data back in name=value pairs instead of as xml....good luck with it

bladeMX
10-19-2002, 12:45 AM
Just talked to my perl guy, and it sure can handle it. Why else would XML be so popular. :)

i just tried the method that you sent me and I get an error when it tries to locate the file through HTTP.

Would I need to load this in a browser window?

Do I need to declare a content-type before I send the XML data to the perl script?

You really know your stuff Jim, thanks again!

jimburton
10-19-2002, 12:57 AM
i just tried the method that you sent me and I get an error when it trie as you use an absolute path ("http...") you should be able to run it locally as long as you're connected to the net.

Re content type, I'd check with your perl guy (I could do with one of those myself :))

bladeMX
11-06-2002, 11:49 PM
Hey Jim,

Thanks again for all your help with this XML/Perl scripting.

My perl guy and I are now able to send and load XML data into flash MX, and verify it using some conditions.

I have a quick question for you regarding standalone players. If I build this app, will the XML.sendAndLoad still work if it is not loaded using a browser? In the end we want to build .exe files that people can use from any computer without having to load it into a browser. If you have any info on please let me know.

Thanks!

jimburton
11-07-2002, 01:58 PM
Glad you got it going! :)

It should work fine if you supply an absolute path in the sendandload command, but I must admit I've never tried those xml methods from an executable myself...

bladeMX
11-23-2002, 06:43 PM
I another issue that i'm having some difficulty with, now.

I have some text fields for user to fill out, which then converts them to XML and send to the perl script.

We want to have multiple text fields, so that if a user fills them out, it will send that data as well. How would that work if the user left some of them blank? Which is fine by the way, but can you append the second string of code to the end of the first xml string?

Here is what I mean:

loginInfo = new XML("<doc><SendNotificationMessage><ServerHandle>"+serverHandle+"</ServerHandle><AreaCode>"+areacode+"</AreaCode><PhoneNumber>"+prefix+""+suffix+"</PhoneNumber><Text>"+message+"</Text><SpeechLanguage></SpeechLanguage><TimeZone></TimeZone><CallTime></CallTime><CallHours></CallHours><Priority></Priority></SendNotificationMessage></doc>");


Now I want to attach the same code a second time to the var loginInfo. Do I seperate that with a comma? Or just attach it along with with the quotes?

Just when you think you are done, things get more complicated. :)

jimburton
11-24-2002, 11:51 AM
not quite sure I understand your question, but to add more xml to an existing xml object I don't think sticking it on the end will work for you - have a read about xml.createElement(), xml.createTextNode() (used to create you elements and give them content) and xml.appendChild() (used to slot the new elemets in at the right place in your xml doc)