rellis32 Posted August 26, 2009 Posted August 26, 2009 (edited) 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, 2009 by Guest
David Jondreau Posted August 26, 2009 Posted August 26, 2009 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.
rellis32 Posted August 26, 2009 Author Posted August 26, 2009 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
David Jondreau Posted August 26, 2009 Posted August 26, 2009 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 )
rellis32 Posted August 26, 2009 Author Posted August 26, 2009 (edited) 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, 2009 by Guest
comment Posted August 26, 2009 Posted August 26, 2009 The more elegant solution would be to import the XML file, using a custom XSLT stylesheet.
rellis32 Posted August 27, 2009 Author Posted August 27, 2009 Thank you both for the help. I did go ahead and implement the import with xsl. Seems to work rather well Again, thank you!
Recommended Posts
This topic is 5903 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now