views:

435

answers:

3

It seems that there is no xml parsing tool in available JSFL (Adobe Flash-extension Javascript script file) : http://osflash.org/pipermail/flashextensibility%5Fosflash.org/2006-July/000014.html

So, is there an easy and cross-platform way to add a javascript xml parser?

A: 
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.

Eli Grey
Sorry but that's what I wanted to do before searching for another solution : DOMParser class don't exist in JSFL and I'm doing a cross-platform script so using ActiveX is not allowed.
Klaim
+1  A: 

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.

Eli Grey
I'll try this once back to work but I don't think it will work as jsfl files are Javascript and not ActionScript files. Lot of similarities but differences too. I'll try anyway and report then.
Klaim
@Klaim u can parse xml with e4x using jsfl ( http://robertpenner.com/flashblog/2007/08/jsfl-updated-to-javascript-16-gains-e4x.html )
George Profenza
A: 

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);
George Profenza