Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with XML recursive Custom function

Featured Replies

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 by Guest

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.

  • 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

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

)

  • 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 :laugh: Thank you very much!

Bob

Edited by Guest

The more elegant solution would be to import the XML file, using a custom XSLT stylesheet.

  • Author

Thank you both for the help. I did go ahead and implement the import with xsl. Seems to work rather well :thumbup:

Again, thank you!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.