topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 4:06 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: XML If-Els  (Read 6324 times)

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
XML If-Els
« on: August 21, 2015, 09:32 PM »
Hi,

I have been working on this problem in Microsoft Flight Simulator 2004 for a couple of days and decided I should probably seek some help.

In the below code I am testing if the TOTAL WEIGHT > 136000 and TOTAL WEIGHT < 140001 then if both statements are true I want to assign the value 139 to the variable "v1."  The problem is the output is "0."  So, what is wrong with the below syntax?  I can't see the problem, but I am not all that good at XML.

<!-- Sets V1 for Flaps 15  -->
      <Element>
         <Select>
            <Value>
               if{ (A:TOTAL WEIGHT,pounds) 136000 &gt;
                  1   if{ (A:TOTAL WEIGHT,pounds) 140001 &lt;
                        1   139 (&gt;L:v1,knots)
                      }
                }
            </Value>
         </Select>
      </Element>



« Last Edit: August 23, 2015, 02:06 PM by CodeTRUCKER »

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #1 on: August 21, 2015, 11:50 PM »
Would something like this not be easier?

Code: Text [Select]
  1. <Element>
  2.     <if>
  3.         <conditions>
  4.             <condition var="TotalWeightMin" operator="&gt;">136000</condition>
  5.             <condition var="TotalWeightMax" operator="&lt;">140001</condition>
  6.         </conditions>
  7.         <statements>
  8.             <V1>
  9.                 <valueV1>139</valueV1>
  10.             </V1>
  11.         </statements>
  12.     </if>
  13. </Element>


Caveat: The stories of my experience with XML can written on the head of one pin.

The W3schools web site says that it is preferable to use conditional statements in a XLST file that is linked to the XML file you are trying to create.

What I do know is that if you want to do more serious work with XML files, you will need a decent XML editor that also allows for debugging. XML Studio is such an editor, but it doesn't come cheap. Perhaps their trial version works long enough for you to grok this type of functionality in XML.

Sorry, can't be of much more help...if all of the above was even helpful at all. 

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #2 on: August 22, 2015, 03:26 AM »
XML does not have any 'programming logic' by itself; as Shades already suggests, an XML processing-tool, like XSLT is required.

I've been enormously helped in the past by the XSLT processing features of NetBeans IDE :Thmbsup: as it has both code-completion and ofc. syntax-highlighting.

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #3 on: August 22, 2015, 03:01 PM »
Thanks for the replies.

I knew XML did not have its own "programming" construct, but the environment (Microsoft Flight Simulator 2004) I am working in uses an XML "IF-ELS" in programming various gauges and functions.  Oddly, if I use either of the If statements above alone, they work, but when I nest them the output is "0" (zero).  So, unless there are any other MSFS gauge developers around, I'm stuck.

Just in case anyone is curious, what is happening is I am automating a chart look-up of flight phase airspeeds called "V-Speeds" (see below).  The routine only runs and updates five times a second.  It examines the ranges of the gross weight and flaps/slats settings and displays a hard-coded value.  Depending on the gross weight of the aircraft the phase airspeed is dynamically displayed on the windshield for the pilot.  These phases or V-Speeds are...
  • V1 - The point at which a go/no go decision is made by the pilot.
  • VR - Having passed V1, takeoff is now committed and the aircraft is angled upwards, but the aircraft is not yet flying, only angled upward and still accelerating.
  • V2 - The airspeed phase where the aircraft can lift off and maintain sustainable and safe flight.
  • There are others, but this gives you an idea.
 

The V-Speeds for real aircraft are produced by a complex mathematical equation including gross weight of the aircraft, flap settings, slats settings, wind, barometric pressure, density altitude, airport altitude, available power from the engines, etc.  Fortunately, I am only working from a simplified gross weight chart that has already been prepared.  I'm only examining the gross weight and flap/slat settings and then displaying the results.

[Thinking out loud]
I wonder if I can arrange the tests without having to nest?
[/Thinking out loud]

I hope this makes sense.

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #4 on: August 22, 2015, 06:38 PM »
I figured it out! 

While this is not what one normally uses XML for, I figured out what the syntax is supposed to be.  Also, this will only work in the confines of flight simulator and for specific aircraft.

A much different construct than the one in the OP...

<!-- Sets V-Speeds for 138000 @ Flaps 15 -->
      <Element>
         <Select>
            <Value>
               (A:TOTAL WEIGHT,pound) 138001 &lt;
                  if{
                     1   (A:TOTAL WEIGHT,pound) 135999 &gt;
                           if{
                              1   (A:FLAPS HANDLE INDEX,enum) 3 ==  // The position of the flaps handle.
                                    if{
                                       1   134 (&gt;L:v1,knots)
                                          140 (&gt;L:vr,knots)
                                          147 (&gt;L:v2,knots)
                                          162 (&gt;L:fr,knots)
                                          194 (&gt;L:sr,knots)
                                    }
                                    els{
                                       0   0 (&gt;L:v1,knots)
                                          0 (&gt;L:vr,knots)
                                           0 (&gt;L:v2,knots)
                                          0 (&gt;L:fr,knots)
                                          0 (&gt;L:sr,knots)
                                    }
                           }
                           els{
                              0   0 (&gt;L:v1,knots)
                                 0 (&gt;L:vr,knots)
                                 0 (&gt;L:v2,knots)
                                 0 (&gt;L:fr,knots)
                                 0 (&gt;L:sr,knots)
                           }
                  }
                  els{
                     0   0 (&gt;L:v1,knots)
                        0 (&gt;L:vr,knots)
                        0 (&gt;L:v2,knots)
                        0 (&gt;L:fr,knots)
                        0 (&gt;L:sr,knots)
                  }
            </Value>
         </Select>
      </Element>
   </Element>


Thanks for the contributions.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #5 on: August 23, 2015, 03:59 AM »
Aha, the FlightSim context was missing from your OP, but I still wouldn't have known about the if/els structures :-[
Could have made an assumption, knowing that you're a 'flight-sim guy', but you know what they say about any assumption...  ;D

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
Re: XML If-Els
« Reply #6 on: August 23, 2015, 02:07 PM »
Aha, the FlightSim context was missing from your OP, but I still wouldn't have known about the if/els structures :-[
...

Thanks for the heads-up.  OP oversight corrected.