在Flash文件中解析XML [英] Parsing XML in a flash file

查看:86
本文介绍了在Flash文件中解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,再次(与pretty的多少我所有的帖子)我有闪光灯几乎一无所知,而我试图达到pretty的复杂的事情,所以请善待你的回应。而且,这一切都是在PC本地发生的事情,所以没有净的问题。

基本上,我有以下生成的XML文件中的第三方程序,它的每一个接收由第三方程序中的新邮件的时间重新编写XML文件。我正在试图做的是找到一种方法在有关FlashVars的读取(如果这是正确的术语)成Flash文件(基本上我想读邮件中1 - 6),忽略XML的其余部分,显示消息,然后重新加载大约每30秒的XML(如果它的改变)。我想这是pretty的很像各种各样的新闻阅读器,但我并没有对XML文件的结构中的任何控制,因此,如果有人可以点我朝着正确的方向排序的话,我很高兴有一个去学习。我曾尝试与我下载了一个基本的新闻阅读器的Flash文件搞乱,但它似乎并没有像XML - 我猜是因为XML中的每个消息都有自己的号码?任何帮助一如既往,大大AP preciated。

谢谢

罗布。

 < XML版本=1.0编码=ISO-8859-1&GT?;
< messagemonitor>

<邮件>

< MESSAGE1>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< / MESSAGE1>

< MESSAGE2>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< / MESSAGE2>

< MESSAGE3>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< / MESSAGE3>

<消息4>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< /消息4>

< MESSAGE5>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< / MESSAGE5>

< message6>
  <使用者>< /使用者>
  <性别>< /性别>
  < genderimagepath> C:/ Program Files文件/监视/ monitorV3 / CONF /表情/ blankgender.gif< / genderimagepath>
  <味精>发送邮件至07654 321 123 LT; /味精>
< / message6>
< /邮件>

<票>
<问题>< /问题>
< 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文件(86)/监控/监控V3 / CONF /表情/ blankgender.gif< /异食癖>
< PICB> C:/ Program Files文件(86)/监控/监控V3 / CONF /表情/ blankgender.gif< / PICB>
< PICC> C:/ Program Files文件(86)/监控/监控V3 / CONF /表情/ blankgender.gif< / PICC>
< picd> C:/ Program Files文件(86)/监控/监控V3 / CONF /表情/ blankgender.gif< / picd>
< /票>

<照片>
< flashmovie>< / flashmovie>
< picturecaption>< / picturecaption>
< PictureFile的>< / PictureFile的>
< slideshowfile>< / slideshowfile>
< combiphotofile>< / combiphotofile>
< /照片>

< SystemInfo的>
<数量> 07654 321 123 LT; /数字>
<系统名称> CHEESEY< /系统名称>
< SendMessage函数>发送邮件至07654 321 123 LT; / SendMessage消息>
< sendvotemsg>发送您的选择,以07654 321 123 LT; / sendvotemsg>
<协议>使用本系统,您同意通过短信从操作或选择的第三方&LT接收报价/促销/协议>
< / SystemInfo的>

< / messagemonitor>
 

解决方案

以下应作为通过普通EX pression匹配的通用节点选择的一个例子。它假定加载的数据是XML,否则将出现解析错误。请注意,这code是只是一个功能性的例子。

下面的XML作为基础此示例:

 <根>
    &其中; TAG1→1&其中; / TAG1>
    &其中;标签2→2&其中; / TAG2>
    &其中; TAG3→3&所述; / TAG3>

    <其它>< /其它>
< /根>
 

下面code将加载,并根据所需的节点上解析:

  VAR装载机:的URLLoader =新的URLLoader();
loader.addEventListener(引发Event.COMPLETE,函数(事件:事件):无效
{
    VAR的xml:XML =新的XML(loader.data);
    VAR消息:。的XMLList = XML *(/ ^标记/ .TEST(名称()));

    跟踪(messages.toXMLString());

    //&其中; TAG1→1&其中; / TAG1>
    //&其中;标签2→2&其中; / TAG2>
    //&其中; TAG3→3&所述; / TAG3>
});

loader.load(新的URLRequest(path_to_xml));
 

这应该可以摆脱一些洞察E4X,因为没有使用正则表达式匹配节点名的例子很多。

祝您好运!

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>

解决方案

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!

这篇关于在Flash文件中解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆