在 JSFL 中解析 XML?

发布于 2024-08-07 03:42:50 字数 322 浏览 8 评论 0原文

似乎可用的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

晨曦慕雪 2024-08-14 03:42:50

我知道这是一个老问题,但我也在寻找这个问题的解决方案(使用 Flash CS3)。我需要从磁盘上的数据文件中解析 XML。结合乔治·普罗芬扎的建议,我能够让它与使用一起使用eval()。关键是删除第一行(xml 声明):

xmlData = eval( FLfile.read( xmlFile ).split( '\n' ).slice( 1 ).join( '\n' ) );

... 就可以开始了!

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):

xmlData = eval( FLfile.read( xmlFile ).split( '\n' ).slice( 1 ).join( '\n' ) );

... and you're good to go!

只是偏爱你 2024-08-14 03:42:50

好吧,您可以使用 Flash CS3 或更新版本的 JSFL 直接使用 XML 和 E4X,如 Javascript 引擎已升级至 1.6

下面是一个快速片段,它循环遍历当前选择中的元素并跟踪 xml:

var doc = fl.getDocumentDOM();//get the current document ref.
var selection = doc.selection;//get the selection
var layout = <layout />;//create the root node for our xml
var elementsNum = selection.length;//store this for counting*
for(var i = 0 ; i < elementsNum ; i++){
   layout.appendChild(<element />);//add an element node
   layout.element[i].@name = selection[i].name;//setup attributes
   layout.element[i].@x = selection[i].x;
   layout.element[i].@y = selection[i].y;
}
fl.trace(layout);

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:

var doc = fl.getDocumentDOM();//get the current document ref.
var selection = doc.selection;//get the selection
var layout = <layout />;//create the root node for our xml
var elementsNum = selection.length;//store this for counting*
for(var i = 0 ; i < elementsNum ; i++){
   layout.appendChild(<element />);//add an element node
   layout.element[i].@name = selection[i].name;//setup attributes
   layout.element[i].@x = selection[i].x;
   layout.element[i].@y = selection[i].y;
}
fl.trace(layout);
゛清羽墨安 2024-08-14 03:42:50
var xml = new XML(FLfile.read(file));

然后,您可以通过编写以下内容来访问所有节点和属性:

xml.nodeName
xml.nodeName.@attribute1
xml.nodeName.@attribute2

nodeName 是节点的名称。
attribute1 应该是您的属性的名称。

我希望这有帮助。

var xml = new XML(FLfile.read(file));

Then you can access all your nodes and attributes by writing this:

xml.nodeName
xml.nodeName.@attribute1
xml.nodeName.@attribute2

nodeName is the name of your node.
attribute1 should be the name of your attribute.

I hope this helps.

蓬勃野心 2024-08-14 03:42:50

如果 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) or XMLList(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.

梦与时光遇 2024-08-14 03:42:50

对我来说最有效的就是创建一个 SwfWindow。在 JSFL 中工作既方便又快捷,因为您可以更改文件而无需重新启动 Flash,但 ActionScript 通常会为您提供更多功能。

我当前的项目采用了一些技巧:

  1. 我将在 JSFL 中创建对象,然后将它们转换为 XML。我必须将它们从对象格式序列化为传递给 SwfWindow(面板)的字符串。我从面板中取出字符串,可以将其转换为 XML。然后您可以在 Actionscript 3.0 中做任何您想做的事情。

  2. 只进行 XML 操作,我将提示用户使用 JSFL 代码输入 XML 文件路径,但将 URL 直接交给面板,然后让面板直接加载 XML。

  3. 最后。为了保存 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:

  1. 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.

  2. 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.

  3. 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.

抠脚大汉 2024-08-14 03:42:50
function parseXML (xml) {
    try { // normal browsers
        return (new DOMParser()).parseFromString(xml, "application/xml");
    }
    catch (e) { // IE
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xml);
        return xmlDoc;
    }
}

您可能想阅读有关 DOMParserMicrosoft.XMLDOM ActiveX 对象。

function parseXML (xml) {
    try { // normal browsers
        return (new DOMParser()).parseFromString(xml, "application/xml");
    }
    catch (e) { // IE
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xml);
        return xmlDoc;
    }
}

You might want to read more on DOMParser and the Microsoft.XMLDOM ActiveX object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文