Reputation: 131
Firstly and once again (as with pretty much all my posts) I have almost no knowledge of flash, and I'm trying to achieve pretty sophisticated things, so please be kind in your response. Also, all this is happening locally on the pc, so no net issues.
Basically, I have a 3rd party programme which generates the xml file below, and it re-writes the xml file every time a new message is received by that 3rd party programme. What I'm trying to do is find a way to read in the relevant flashvars (if that's the right term) into a flash file (basically I want to read in messages 1 - 6), ignore the rest of the xml, display the messages and then re-load the xml about every 30 seconds (in case it's changed). I guess this is pretty much like a news reader of sorts, but I don't have any control over the structure of the xml file, so if someone could point me in the right sort of direction, then I'm happy to have a go at learning. I did try messing with a basic news reader flash file that I downloaded, but it didn't seem to like the xml - I guess because each message in the xml has its own number? any help as always, greatly appreciated.
Thanks,
Rob.
<?xml version="1.0" encoding="iso-8859-1"?>
<messagemonitor>
<messages>
<message1>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message1>
<message2>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message2>
<message3>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message3>
<message4>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message4>
<message5>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message5>
<message6>
<user></user>
<gender></gender>
<genderimagepath>C:/Program Files/monitor/monitorV3/Conf/Emoticons/blankgender.gif</genderimagepath>
<msg>Send your Messages to 07654 321 123</msg>
</message6>
</messages>
<votes>
<question></question>
<answera></answera>
<answerb></answerb>
<answerc></answerc>
<answerd></answerd>
<answere></answere>
<answerf></answerf>
<votepercenta></votepercenta>
<votepercentb></votepercentb>
<votepercentc></votepercentc>
<votepercentd></votepercentd>
<votepercente></votepercente>
<votepercentf></votepercentf>
<votepercentnuma></votepercentnuma>
<votepercentnumb></votepercentnumb>
<votepercentnumc></votepercentnumc>
<votepercentnumd></votepercentnumd>
<votepercentnume></votepercentnume>
<votepercentnumf></votepercentnumf>
<pica>C:/Program Files (x86)/monitor/Monitor V3/Conf/Emoticons/blankgender.gif</pica>
<picb>C:/Program Files (x86)/monitor/Monitor V3/Conf/Emoticons/blankgender.gif</picb>
<picc>C:/Program Files (x86)/monitor/Monitor V3/Conf/Emoticons/blankgender.gif</picc>
<picd>C:/Program Files (x86)/monitor/Monitor V3/Conf/Emoticons/blankgender.gif</picd>
</votes>
<photos>
<flashmovie></flashmovie>
<picturecaption></picturecaption>
<picturefile></picturefile>
<slideshowfile></slideshowfile>
<combiphotofile></combiphotofile>
</photos>
<systeminfo>
<number>07654 321 123</number>
<systemname>CHEESEY</systemname>
<sendmessage>Send your Messages to 07654 321 123</sendmessage>
<sendvotemsg>Send your Selection to 07654 321 123</sendvotemsg>
<agreement>By using this system you agree to receive offers / promotions via SMS from the operator or selected 3rd parties</agreement>
</systeminfo>
</messagemonitor>
Upvotes: 1
Views: 434
Reputation: 411
The following should serve as an example for generic node selection via regular expression matching. It assumes the loaded data is xml, otherwise a parse error would occur. Please note, this code is merely a functional example.
The following xml serves as the basis for this example:
<root>
<tag1>1</tag1>
<tag2>2</tag2>
<tag3>3</tag3>
<misc>?</misc>
</root>
The following code would load and parse based on the desired nodes:
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, function(event:Event):void
{
var xml:XML = new XML(loader.data);
var messages:XMLList = xml.*.(/^tag/.test(name()));
trace(messages.toXMLString());
// <tag1>1</tag1>
// <tag2>2</tag2>
// <tag3>3</tag3>
});
loader.load(new URLRequest("path_to_xml"));
Hopefully this should shed some insight into e4x, since there are not many examples of using a regex to match node names.
Best of luck!
Upvotes: 3
Reputation: 15955
Assuming your service was loaded in to a XML variable named xml
, you would iterate the children of xml.messages
:
var xml:XML; // loaded XML per your cited example.
for each (var messageXml:XML in xml.messages.children())
{
trace("User: " + messageXml..user.toString());
trace("Gender: " + messageXml..gender.toString());
// etc...
}
Upvotes: 0