1

似乎在可用的 JSFL(Adobe Flash 扩展 Javascript 脚本文件)中没有 xml 解析工具:http: //osflash.org/pipermail/flashextensibility_osflash.org/2006-July/000014.html

那么,是否有一种简单且跨平台的方法来添加 javascript xml 解析器?

4

6 回答 6

3

我知道这是一个老问题,但我也在寻找解决这个问题的方法(使用 Flash CS3)。我需要从磁盘上的数据文件中解析 XML。结合George Profenza 的建议,我能够使用eval(). 关键是删除第一行(xml声明):

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

......你很高兴去!

于 2011-08-24T16:00:57.983 回答
2

好吧,随着Javascript 引擎升级到 1.6 ,您可以使用 Flash CS3 或更高版本直接从 JSFL 使用 XML 和 E4X

这是一个快速的片段,它遍历当前选择中的元素并跟踪 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);
于 2010-07-03T15:57:20.140 回答
2
var xml = new XML(FLfile.read(file));

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

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

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

我希望这有帮助。

于 2014-10-10T06:07:24.570 回答
1

如果 JSFL 在某些时候使用 ActionScript,那么只要它是 ActionScript 3.0 或更高版本就可以XML(xml_string)XMLList(multiple_xml_nodes_string)ActionScript 3.0 支持 E4X,即 ECMAScript 中的原生 XML。

于 2009-10-01T21:48:27.513 回答
0

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.

于 2010-11-12T19:03:50.177 回答
-2
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 对象的信息。

于 2009-09-30T20:36:25.137 回答