Jump to content

Help with XML recursive Custom function


This topic is 5377 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This topic is 5377 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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