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.
>>
>> _______________________________________________
>> [email protected]
>> 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
>>
>
> _______________________________________________
> [email protected]
> 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
_______________________________________________
[email protected]
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
_______________________________________________
[email protected]
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