Sign in to follow this  

Making Functions in XML - Tutorial

Recommended Posts

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

Share this post

Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

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
Sign in to follow this