return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Parsing XML in JSFL? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Parsing XML in JSFL? - Stack Overflow

programmeradmin3浏览0评论

It seems that there is no xml parsing tool in available JSFL (Adobe Flash-extension Javascript script file) : /2006-July/000014.html

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

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

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

Share Improve this question asked Sep 30, 2009 at 16:08 KlaimKlaim 69.9k36 gold badges135 silver badges190 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 3

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!

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);
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.

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.

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.

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.

发布评论

评论列表(0)

  1. 暂无评论