在 JSFL 中解析 XML?
似乎可用的 JSFL(Adobe Flash-extension Javascript 脚本文件)中没有 xml 解析工具: http://osflash.org/pipermail/flashextensibility_osflash.org/2006-July/000014.html
那么,有没有一种简单且跨平台的方法来添加 javascript xml 解析器?
It seems that there is no xml parsing tool in available JSFL (Adobe Flash-extension Javascript script file) : http://osflash.org/pipermail/flashextensibility_osflash.org/2006-July/000014.html
So, is there an easy and cross-platform way to add a javascript xml parser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道这是一个老问题,但我也在寻找这个问题的解决方案(使用 Flash CS3)。我需要从磁盘上的数据文件中解析 XML。结合乔治·普罗芬扎的建议,我能够让它与使用一起使用
eval()
。关键是删除第一行(xml 声明):... 就可以开始了!
I know this is an old question, but I was looking for a solution to this problem as well (using Flash CS3). I needed to parse XML from a data file on disk. Combining the suggestion of George Profenza I was able to get it to work with using
eval()
. The key is to remove the first line (the xml declaration):... and you're good to go!
好吧,您可以使用 Flash CS3 或更新版本的 JSFL 直接使用 XML 和 E4X,如 Javascript 引擎已升级至 1.6
下面是一个快速片段,它循环遍历当前选择中的元素并跟踪 xml:
Well, you can use XML and E4X straight from JSFL using Flash CS3 or newer as the Javascript engine got upgraded to 1.6
Here's a quick snippet that loops through elements in the current selection and traces xml:
然后,您可以通过编写以下内容来访问所有节点和属性:
nodeName 是节点的名称。
attribute1 应该是您的属性的名称。
我希望这有帮助。
Then you can access all your nodes and attributes by writing this:
nodeName is the name of your node.
attribute1 should be the name of your attribute.
I hope this helps.
如果 JSFL 在某些时候使用 ActionScript,则只需使用
XML(xml_string)
或XMLList(multiple_xml_nodes_string)
,只要它是 ActionScript 3.0 或更高版本即可。 ActionScript 3.0 支持 E4X,它是 ECMAScript 中的本机 XML。If JSFL uses ActionScript at some point, you can just do
XML(xml_string)
orXMLList(multiple_xml_nodes_string)
as long as it's ActionScript 3.0 or higher. ActionScript 3.0 supports E4X witch is native XML in ECMAScript.对我来说最有效的就是创建一个 SwfWindow。在 JSFL 中工作既方便又快捷,因为您可以更改文件而无需重新启动 Flash,但 ActionScript 通常会为您提供更多功能。
我当前的项目采用了一些技巧:
我将在 JSFL 中创建对象,然后将它们转换为 XML。我必须将它们从对象格式序列化为传递给 SwfWindow(面板)的字符串。我从面板中取出字符串,可以将其转换为 XML。然后您可以在 Actionscript 3.0 中做任何您想做的事情。
最后。为了保存 XML,我必须通过“xml.toXmlString()”将 XML 转换为字符串,但您还需要删除“\n”,以便可以将数据交给 JSFL。我将删除“|”的“\n”或者任何你喜欢的东西。然后将字符串传递给 JSFL,然后您可以反序列化该字符串并更改“|”返回“\n”并保存文件。使用较旧的“保存输出面板”方法,或使用较新的文件写入方法。
希望有帮助。
What works nicely for me is just creating a SwfWindow. Working in JSFL is nice and fast because you can change out the file without having to restart Flash, but often ActionScript gives you more power.
My current project does a couple tricks:
I will create objects in JSFL and then convert them to XML. I have to serialize them from Object format into a string which I pass to the SwfWindow (Panel). From the Panel, I take the String can convert it into XML. Then you can do anything you want in Actionscript 3.0.
If I just have XML manipulation, I will prompt the User for a XML files path in JSFL code, but hand the URL directly to the Panel, and have the Panel just load the XML directly.
Finally. For saving the XML, I will have to convert the XML to string via, 'xml.toXmlString()', but you also need to remove the '\n' so that you can hand the data to JSFL. I will strip out the '\n' for '|' or whatever you like. Then pass the string to JSFL, and you then can deserialize the string and change the '|' back to '\n' and save the file. Either using the older 'Save Output Panel' method, or using the newer File Write method.
Hope that helps.
您可能想阅读有关 DOMParser 和 Microsoft.XMLDOM ActiveX 对象。
You might want to read more on DOMParser and the Microsoft.XMLDOM ActiveX object.