Breaking out of recursive handler and returning result does not happen
Breaking out of recursive handler and returning result does not happen
- Subject: Breaking out of recursive handler and returning result does not happen
- From: Andreas Mixich <email@hidden>
- Date: Sun, 23 Oct 2011 22:13:52 +0200
Hello,
I try to find a node in an XML tree, in order to return the XML
fragment, contained in this node. It seems, that "System Event"'s XML
library does not automatically traverse through the complete XML tree,
but I need to do it myself. So I wrote this recursive handler, that
travels through each element and checks for the ID I am searching.
on run {}
tell application "System Events"
set myXMLFile to XML file "/Users/ada/Desktop/test.xml"
set myXMLData to every XML element of the contents of the contents
of myXMLFile
my _parseXMLElements(myXMLData)
end tell
end run
-- this recursive handler travels through each element of the document
on _parseXMLElements(theList)
tell application "System Events"
repeat with currentItem in theList
log "1"
log (get the name of the currentItem)
log (get the value of the currentItem)
repeat with currentAttribute in XML attributes of currentItem
log "2"
log (get name of currentAttribute)
log (get value of currentAttribute)
if value of the currentAttribute is "tma-25" then
set myFindings to currentItem
return myFindings
end if
end repeat
repeat with currentItem2 in every XML element of currentItem
log "3"
log (get the value of the currentItem2)
my _parseXMLElements(currentItem2)
end repeat
end repeat
end tell
end _parseXMLElements
The first strangeness was, that I could not test for the 'id' itself.
This is why I implemented the explicit checking for the 'id'.
The other, my main problem is, that I can not return the XML fragment
and I find no way out of the loop, when I found it. 'return
myFindings' does not return out of the handler. 'continue
_parseXMLElements(theList)' is not a sensible way either. Also 'exit'
does not quit the routine, when I thought it should do. In addition I
do not get 'myFindings'
It seems, that both 'return' and 'exit' leave only the current loop,
but not the handler. That could be done by 'continue' as far as I have
understood, but it seems counterproductive, since 'continue' requires
me to add a handler's name, along with the options, which makes no
fricking sense to me, since this is the handler I want to leave, not
the one I want to continue. Also, I have so sensible option to pass.
What am I doing wrong? Thanks so much.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden