February 20, 200521 yr Commercial Member Hey all,I thought I'd share this information on making XML 'functions' in the hopes that it might be useful to some of you. I've been getting a number of inquiries lately on the subject, so maybe this will save me some time as well:)A function in (MS)XML is actually a 'macro' which is passed a number of arguments. Just like most other languages functions allow you to create re-useable code.For this example I'll start with a simple function that converts degrees to radians and takes only one argument - something you can already do with the built-in 'dgrd' function, but still useful for illustrative purposes.1) Define the macro function: @1 pi 180 / *'@1' represents the argument.2) Call the function:@DegRad((A:Plane Heading Degrees True, degrees))Returns heading in radians. Now for something a bit more complex. This function returns the great circle distance between two sets of coordinates:1) Define the macro:@1 sin @3 sin * @1 cos @3 cos * @2 @4 - cos * + acos Where: @1 = LAT1 @2 = LON1 @3 = LAT2 @4 = LON22) Calling the function: @GC_DISTANCE((A:PLANE LATITUDE, radians), (A:PLANE LONGITUDE, radians), (A:GPS WP NEXT LAT, radians) (A:GPS WP NEXT LON, radians))Returns the great circle distance between the two sets of coordinates.While this function is not terribly useful because the distance is already available as a GPS var, it does demonstrate how to pass multiple arguments. I use this, and other functions like it, to manipulate my own sets of coordinates. The main point here is that what otherwise would be very sloppy and hard to read code, can be cleaned up quite a bit by using this undocumented method.One can also use another function as an argument:Syntax for calling a function:@Function_Name([arg_1], [arg_2], [arg_3], [arg_n])Results are passed to the top of the stack.Hope this is helpful...--Jon Jon Blum Vertical Reality Simulations
Create an account or sign in to comment