August 26, 200916 yr I would like to have a custom function that returns a delimited list of results when passed the xml source and the xml tag. xmlGetAll(theXML ; theTag) this is what i have so far Let ( [ tagNumber = PatternCount ( theXML ; theTag ); tagLength = Length(theTag); tagStart = Position ( theXML ; "<" & theTag & ">" ; 1 ; 1 ) + tagLength + 2 ; tagEnd = Position ( theXML ; "" & theTag & ">" ; 1 ; 1 ); tagLen = tagEnd - tagStart ]; If ( tagNumber > 0 ; Middle ( theXML ; tagStart ; tagLen ) ; "") ) This works fine for finding the first occurance, what I am struggling with is wrapping my head around how to make it recursive. I have used a script to do this in the past but I think a cf would be a better solution. Any help is greatly appreciated. Edited August 26, 200916 yr by Guest
August 26, 200916 yr I don't know XML, but if you post an sample input and output, I could help. A recursive function calls itself. I don't know if you need one here, but if you did, you would need to put the conditions in which you want it to recurse, along with another call to the function itself.
August 26, 200916 yr Author I would like to put in: xmlGetAll ( theXML ; theTag ) where theXML = 628120 628195.26 628565.42 628746.44 628966.93 628916.93 628257.23 628227.47 628977.86 628408.03 628368.19 628058.94 628849.54 and theTag = ZIP_CODE and the result is: 62812 62819 62856 62874 62896 ....etc basically I have a php script which, when give a zip code and a radius, returns the xml above. I need to pull the zip codes into a field to be used in a multikey relationship. Hope this makes it a little more clear as to what I am trying to accomplish. Bob
August 26, 200916 yr There may be a more elegant solution, but this should get the job done: Let([ open = "<" & theTag & ">" ; close = "" & theTag & ">"; start = Position ( theXML ; open ; 1 ; 1) + Length(open); end = Position(theXML; close;1;1 ); lenData = end - start; thisVal= Middle ( theXML ; start; lenData); lenClose = Length(end); newXMLStart = end + lenClose + 1; newXML = Replace(theXML; 1; newXMLStart;""); recurse = PatternCount(newXML; theTag); pil = If(recurse > 1; ¶); result = thisVal & pil & Case(recurse; xmlGetAll(newXML; theTag)) ]; result )
August 26, 200916 yr Author I'm not a judge of elegance, all that matters is it works like a charm! Also, it in such a manner that I can see what is taking place, kind of like running a script Thank you very much! Bob Edited August 26, 200916 yr by Guest
August 26, 200916 yr The more elegant solution would be to import the XML file, using a custom XSLT stylesheet.
August 27, 200916 yr Author Thank you both for the help. I did go ahead and implement the import with xsl. Seems to work rather well Again, thank you!
Create an account or sign in to comment