Skip to content

Validation of aircraft XML definition file#1038

Merged
bcoconni merged 4 commits intoJSBSim-Team:masterfrom
bcoconni:XML-aircraft-validation
Sep 27, 2025
Merged

Validation of aircraft XML definition file#1038
bcoconni merged 4 commits intoJSBSim-Team:masterfrom
bcoconni:XML-aircraft-validation

Conversation

@bcoconni
Copy link
Member

@bcoconni bcoconni commented Feb 11, 2024

This PR contributes to addressing the issue #155. It updates the XML validation document JSBSim.xsd to (nearly ?) match the current state of aircraft definition files format. Some code has been moved from JSBSimScript.xsd and JSBSimSystems.xsd to JSBSimCommon.xsd to reduce redundancy.

Disclaimer

That's a very long introductory comment for a PR and it will most likely be affected by the bike-shed effect a.k.a. law of triviality. I have mostly created it to initiate the discussion. There are a number of choices I made that certainly need to be reviewed and in all likeliness, I'll have to break this PR down into several PR's to make it easier to review.

Consider this PR as a basis for discussion. It is not meant to be merged as is. I have chosen the form of a PR because the changed files show what the result would look like.

Limitations

One of the main limitation to the XSD format is that it does not allow configurations where you could have as many sections as you want in whichever order that suits you. Actually one have to pick one option between the following ones:

  1. Using <xs:sequence>: allows as many instances of each section as the user deems so but the order is imposed.
  2. Using <xs:all>: allows at most one instance of each section without restriction on the order in which they are listed.

Limitations of <xs:sequence>

For example, using <xs:sequence> if the following file validates:

<fdm_config>
  <aerodynamics/>
  <output/>
  <output/>
</fdm_config>

then the same file with a different order of sections is rejected:

<fdm_config>
  <output/> <!-- Error: was expecting 'aerodynamics' -->
  <aerodynamics/>
  <output/>
</fdm_config>

Limitations of <xs:all>

Using <xs:all> validates the following files:

<fdm_config>
  <aerodynamics/>
  <output/>
</fdm_config>
<fdm_config>
  <output/>
  <aerodynamics/>
</fdm_config>

but rejects this file as there are 2 instances of <output/>:

<fdm_config>
  <aerodynamics/>
  <output/>
  <output/>
</fdm_config>

Mitigation for JSBSim

In JSBSim there are a number of models that allows multiple <output> elements or so. For such models the only available option is <xs:sequence>. The consequence is that for XML validation to succeed, an aircraft definition file must meet the following order:

<fdm_config>
    <fileheader/>         <!-- exactly 1 occurrence -->
    <planet/>             <!-- at most 1 occurrence -->
    <metrics/>            <!-- exactly 1 occurrence -->
    <mass_balance/>       <!-- exactly 1 occurrence -->
    <ground_reactions/>   <!-- at most 1 occurrence -->
    <external_reactions/> <!-- at most 1 occurrence -->
    <buoyant_forces/>     <!-- at most 1 occurrence -->
    <propulsion/>         <!-- at most 1 occurrence -->
    <system/>             <!-- any number, or <autopilot/> or <flight_control/> -->
    <aerodynamics/>       <!-- at most 1 occurrence -->
    <input/>              <!-- any number of occurrences -->
    <output/>             <!-- any number of occurrences -->
</fdm_config>

Notes

  1. This order is completely arbitrary and is open for discussion. It was chosen based on legacy and mostly empirically while trying to make all aircraft definition files validate.
  2. @andgi made a comment XML validation #155 (comment) that states that the order in which the sections above are supplied matter. I'd appreciate to have some examples so that we can discuss how to address this. At least in theory the C++ code is order independent: the order in which XML files are processed by JSBSim is imposed by the C++ code, not by the order in which the items are written in the XML file.
  3. Validating file will remain optional so if some users do not want to meet the above order requirement then JSBSim will still be able to run their models. However they will lack the benefit of checking their models for typos, unsupported features, etc.

Results/Achievements

There are good reasons to validate XML files:

  • It makes all the XML files consistent.
    • For example, one can use tags that are unknown to JSBSim. Such tags will be plainly ignored by JSBSim which is OK if is the user intent but is wrong if the tag has been misspelled.
    • The sections will be at the same place from one aircraft definition to the other. Which, at least within JSBSim repository, can help one to review and understand how the FDM are designed.

Modifications

Example

There was a great deal of variation (and creativity !) in the way in which <fileheader> was filled. The proposed schema is

<fileheader>
    <author/>           <!-- any number, or <email/> or <organization/> -->
    <license/>          <!-- at most 1 occurence -->
    <sensitivity/>      <!-- at most 1 occurrence -->
    <filecreationdate/> <!-- at most 1 occurrence -->
    <version/>          <!-- at most 1 occurrence -->
    <copyright/>        <!-- at most 1 occurrence -->
    <description/>      <!-- at most 1 occurrence -->
    <limitation/>       <!-- any number, or <reference/> -->
</fileheader>

Note XSD do not allow spaces around dates so you will find a number of changes such as:

- <filecreationdate> 2024-02-11 </filecreationdate>
+ <filecreationdate>2024-02-11</filecreationdate>

There are a lot of changes of that kind, I will not review them in details here but I'd be happy to discuss them below.

Errors found

Extra name="POINTMASS"

There is a lot of occurrences of <location name="POINTMASS"/> in <pointmass/> items. The attribute name in <location> is not used by JSBSim so I removed it.

Extra <product> around <table>

There is a lot of occurrences of the following sequence of tags:

<product>
 <table>
  ...
 </table>
</product>

Here the <product> item is useless as there is only one item provided (and <product> needs at least 2 to compute a result). In such a case, JSBSim issues a warning and ignores <product> but it is better if the extra <product> would be removed which I did.

Ignored <aerosurface_scale>

In the aircraft B747 there is an <aerosurface_scale> that is included in a <kinematic> element. In such a case, JSBSim silently ignores <aerosurface_scale>. This was most likely a copy-paste error that can easily be detected by XSD schemas

<aerosurface_scale name="Flap Position Normalizer">
<input>fcs/flap-pos-deg</input>
<domain>
<min>0</min> <!-- Flaps actual minimum position -->
<max>30</max> <!-- Flaps actual maximum position -->
</domain>
<range>
<min>0</min> <!-- Flaps normalized minimum position -->
<max>1</max> <!-- Flaps normalized maximum position -->
</range>
<output>fcs/flap-pos-norm</output>
</aerosurface_scale>
</kinematic>

Potato or Potato ? i.e. <description> or <documentation> ?

There are a whole lot of occurrences of the <documentation> tag which is illegal per the legacy JSBSim.xsd. As their name implies, these tags are for documentation and are plainly ignored by JSBSim. In this PR, I've followed the legacy and replaced all occurrences of <documentation> by <description>. Retrospectively I'd allow both so that there are less file modifications.

I have also replaced all occurrences of <description> under the <tank> element by XML comments <!-- --> (see the aircraft B17). There again, we could allow the occurrence of a <description> tag for <tanks> and that would reduce the size of the PR.

@seanmcleod
Copy link
Member

@bcoconni in terms of the order of elements within <fdm_config> I'm assuming you didn't go through all the aircraft in the repo and change the order manually? I'm assuming you wrote a script to do that? Would be useful to provide such a script to users so that they can use it to re-order their aircraft models.

@bcoconni
Copy link
Member Author

bcoconni commented Mar 1, 2024

I'm assuming you didn't go through all the aircraft in the repo and change the order manually?

No I did change the order manually. It should indeed be feasible to write a script but I was afraid that it would change the tabulation layout of the files which would make the diff hardly legible.

@bcoconni bcoconni force-pushed the XML-aircraft-validation branch from 410fdac to a6f27dc Compare September 21, 2025 13:29
@codecov
Copy link

codecov bot commented Sep 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 24.90%. Comparing base (c6efaab) to head (570c2bd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1038   +/-   ##
=======================================
  Coverage   24.90%   24.90%           
=======================================
  Files         169      169           
  Lines       19669    19669           
=======================================
  Hits         4898     4898           
  Misses      14771    14771           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bcoconni bcoconni force-pushed the XML-aircraft-validation branch from a6f27dc to 570c2bd Compare September 21, 2025 13:42
@bcoconni bcoconni marked this pull request as ready for review September 21, 2025 14:03
@bcoconni
Copy link
Member Author

I've pushed an update to this (old) PR that allows using <documentation> in a number of places. This simplifies the aircraft diff's for an easier review.

Let me know what you think.

@seanmcleod70
Copy link
Contributor

Looks good.

@agodemar
Copy link
Contributor

Looks good. Green light to merge?

@andgi
Copy link
Collaborator

andgi commented Sep 22, 2025 via email

@bcoconni
Copy link
Member Author

Hi @andgi

Is it fully tested that aircraft that works in JSBSim (now) but do not pass this test can simple be rearranged to pass the test?

This PR does not modify how JSBSim parses the XML files. So models will still behave the same way.

The order in which the XML is parsed is hardcoded in JSBSim and is independent of the order in which the FDM sections are entered in the XML files. So the reordering that is needed to pass the XML validation should not alter how JSBSim runs the models.

I have some {air,sea}craft where I think the order of the different sections (systems etc.) in the JSBSim files seem to be important. Like these ones:
https://github.com/andgi/FlightGear-MTB_20m
https://github.com/andgi/FlightGear-Nordstern
https://github.com/andgi/FlightGear-ZNP-K
https://github.com/andgi/FlightGear-MFI-9

We would be very interested in having examples that demonstrate the order-dependent behavior that you mentioned. If you could provide an FDM which gives different results based on the order in which the sections (<metrics>, <propulsion>, <aerodynamics>, etc.) are entered that would help very much in addressing this topic.

@bcoconni
Copy link
Member Author

Looks good. Green light to merge?

@agodemar @seanmcleod70 As far as I am concerned, the light is green.

The issue that @andgi has reported is not affected by this PR, and the XML validation is optional. So users can elect not to pass the validation with our schemas (the *.xsd files) if that suits their goals.

Also I would suggest to address the topic mentioned by @andgi in a specific issue as soon as we get an example that demonstrates the XML order dependent behavior.

@andgi
Copy link
Collaborator

andgi commented Sep 23, 2025 via email

@bcoconni bcoconni merged commit c455897 into JSBSim-Team:master Sep 27, 2025
29 checks passed
@bcoconni bcoconni deleted the XML-aircraft-validation branch September 27, 2025 10:12
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants