ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

XML If-Els

(1/2) > >>

CodeTRUCKER:
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>



Shades:
Would something like this not be easier?


--- Code: Text ---<Element>    <if>        <conditions>            <condition var="TotalWeightMin" operator="&gt;">136000</condition>            <condition var="TotalWeightMax" operator="&lt;">140001</condition>        </conditions>        <statements>            <V1>                <valueV1>139</valueV1>            </V1>        </statements>    </if></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:
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:
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:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version