Re: [Flashcoders] XPathAPI recursive XML search
The XPath implementation of XFactorStudio has this built in. There you can do: XPath.selectNodes(xml, //element); to get all nodes whereever that qualitfy. Unfortunately, looks like the XFactorStudio domain is no longer.. I have placed the code I have (and we are still using) here: http://www.yourportfolio.nl/xpath.zip so you can try if you want. The syntax is in some minor calls a little different, but it can do more then Macromedia's XPath as far as I can recall. greetings, Joeri On 2/28/07, T. Michael Keesey [EMAIL PROTECTED] wrote: On 2/26/07, Jim Cheng [EMAIL PROTECTED] wrote: Unfortunately, Flash has never had a good means to traverse an XML tree. Never say never. AS3.0's e4x is an extremely good means for traversing an XML tree. (You're right if you mean pre-AS3 Flash, though.) -- Mike Keesey ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
Tom Klepl wrote: Thanks for the reply.. unfortunately this only returns matching nodes below the parent node specified. What I need is to crawl the XML tree and find ALL matching nodes, regardless of where they are in the tree. Unfortunately, Flash has never had a good means to traverse an XML tree. Macromedia's XPath API is a decent improvement to the out-of-the-box functionality, but if you need to do deep searches into your XML tree of the sort like the W3C DOM's getElementsByName and getElementById calls, you'll have to do it yourself. I have previously written an open-source GPL implementation of the standards based W3C DOM Level 3 Core Specification for ActionScript 2 and wound up writing the traversal algorithms myself. Unless you really need a lot of the W3C DOM API though, I'd suggest sticking with the native XML implementation as it's about an order-of-magnitude faster than mine here: http://www.sourceforge.net/projects/ugo/ I made a quick and dirty rewrite of the pre-order traversal algorithm suitable for use with the native ActionScript 2.0 XMLNode object (as seems to be your case) below at the end of this message. Should you need to traverse your XML tree in some other order, you can fairly easily change the while loop structure to accomodate this. If you need help doing this, you can probably compare against my implementation of the traverse method in the DOM3 Node class in the above project. Hope this helps, Jim Cheng effectiveUI code /** * Steps through an XML tree, calling the function on each node. * * @param The function to call on each node. * @param The root node of the XML tree to traverse. */ function traverse(f:Function, rootNode:XMLNode):Void { var nodeList:Array = [rootNode], nodeList2:Array; var n:XMLNode, i:Number; // Pre-order traversal while(n = XMLNode(nodeList.shift())) { f(n, rootNode); if (n.childNodes.length) { nodeList2 = []; for (i = 0; i n.childNodes.length; i++) { nodeList2.push(n.childNodes[i]); } nodeList = nodeList2.concat(nodeList); } } } // Now look for nodes named nameOfNode var foundNodes:Array = []; function isMatchingNode(n:XMLNode, root:XMLNode):Void { if (n.localName == nameOfNode) { foundNodes.push(n); } } traverse(isMatchingNode, myXMLTree); /code ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
cant remember where i found this, but i use it quite a lot. Just drop the xml root node in as your source node and it will return an array of all node names that match your query string. /* ** Function: findAllTag(source:XMLNode, key:String):Array ** ** Purpose: Recursively searches for, then returns an array **of all XMLNodes whose name match the key. ** **Accepts: source:XMLNode - node to begin the search at **key:String - string to seach nodeNames for **Returns:an array of all XMLNodes whose name match the **key (case insensitive) ** */ function findAllTag(source:XMLNode, key:String):Array { var array:Array = new Array(); var currentNode:XMLNode = source; while (currentNode != null) { //search root node - case insensitive if (currentNode.nodeName.toLowerCase() == key.toLowerCase()) { array.push(currentNode); } if (currentNode.hasChildNodes()) { var tempNode:XMLNode = currentNode.firstChild; // recursively search all child nodes var tempArr:Array = findAllTag(tempNode, key); for (var i = 0; i tempArr.length; ++i) { array.push(tempArr[i]); } } // then search siblings of the root node currentNode = currentNode.nextSibling; } return array; } On 27/02/07, Tom Klepl [EMAIL PROTECTED] wrote: Thanks for the reply.. unfortunately this only returns matching nodes below the parent node specified. What I need is to crawl the XML tree and find ALL matching nodes, regardless of where they are in the tree. Tom Quoting [EMAIL PROTECTED]: I believe: XPathAPI.selectNodeList(node,/*/nameOfNode); will return an array of all child nodes with nameOfNode as their nodeName On Feb 23, 2007, at 5:39 PM, Tom Klepl wrote: Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
If you start at the top of the tree everything that you want is below you. Tom Klepl wrote: Thanks for the reply.. unfortunately this only returns matching nodes below the parent node specified. What I need is to crawl the XML tree and find ALL matching nodes, regardless of where they are in the tree. Tom Quoting [EMAIL PROTECTED]: I believe: XPathAPI.selectNodeList(node,/*/nameOfNode); will return an array of all child nodes with nameOfNode as their nodeName On Feb 23, 2007, at 5:39 PM, Tom Klepl wrote: Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
function getNodes(xmlDoc, tagname, xmlObjArray, isFirst):Array{ if(xmlObjArray == null){ yourArr = new Array(); }else{ yourArr = xmlObjArray; } if(xmlDoc.hasChildNodes()){ for(var i=0; i xmlDoc.childNodes.length; i++){ if( (xmlDoc.childNodes[i].nodeType == 1) (xmlDoc.childNodes[i].nodeName == tagname)){ //code here } yourArr.push(page); } getNodes(xmlDoc.childNodes[i], tagname, yourArr); } } if (isFirst == true) { //trace(finished!); return yourArr; } Does this help? Andrew On 26 Feb 2007, at 16:43, Tom Klepl wrote: Thanks for the reply.. unfortunately this only returns matching nodes below the parent node specified. What I need is to crawl the XML tree and find ALL matching nodes, regardless of where they are in the tree. Tom Quoting [EMAIL PROTECTED]: I believe: XPathAPI.selectNodeList(node,/*/nameOfNode); will return an array of all child nodes with nameOfNode as their nodeName On Feb 23, 2007, at 5:39 PM, Tom Klepl wrote: Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
Thanks for the reply.. unfortunately this only returns matching nodes below the parent node specified. What I need is to crawl the XML tree and find ALL matching nodes, regardless of where they are in the tree. Tom Quoting [EMAIL PROTECTED]: I believe: XPathAPI.selectNodeList(node,/*/nameOfNode); will return an array of all child nodes with nameOfNode as their nodeName On Feb 23, 2007, at 5:39 PM, Tom Klepl wrote: Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] XPathAPI recursive XML search
Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] XPathAPI recursive XML search
I believe: XPathAPI.selectNodeList(node,/*/nameOfNode); will return an array of all child nodes with nameOfNode as their nodeName On Feb 23, 2007, at 5:39 PM, Tom Klepl wrote: Hi.. I am working on a project currently and I'm using Macromedia's XPathAPI. However, I need to recursively search one of my XML files which is 4 or 5 levels deep. The search I want to perform should return all nodes with a specified name, no matter where they are in the hierarchy. Can anyone suggest/point me to a solution? I don't want to use xfactorstudio's API due to its size. I am thinking of extending XPathAPI. Thanks. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com