Menu

#255 Updater writes invalid emitter description (national nomenclature) when CR tries to remove entry

v34
assigned
None
2024-09-11
2024-03-11
John Shue
No

Updater is producing invalid XML when CR attempts to remove the national nomenclature. The XML file contains a space for the description attribute (used for the national nomenclature value).

This is occurring on CR 5041 row 45:

Change Type Value National Nomenclature NATO Reporting Name Commercial Designation Comment (not included in XML DB or products) Footnote (included in XML DB and products) UUID
Update 26935 SA-26 Pechora-2M TT

The cell for National Nomenclature is empty.

Stepping through the code for Updater shows that the value is coming out of the CR as an empty string, but when the file is saved as XML it contains a " ".

Before

    <enumrow value="26935" description="SA Pechora 2M TT" uuid="1cc62799-54f9-472b-8a39-10d9a7c4416c">
      <cr value="2853" />
    </enumrow>

After:

    <enumrow value="26935" description=" " uuid="1cc62799-54f9-472b-8a39-10d9a7c4416c" status="new">
      <cr value="2853" />
      <cr value="5041" />
      <meta key="natoid" value="SA-26 Pechora-2M TT" />
    </enumrow>

The space character is causing the Validator to give the following error:

Fatal error: XML schema validation error at line 77212, column 28: The 'description' attribute is invalid - The value ' ' is invalid according to its datatype 'String' - The Pattern constraint failed.

Discussion

  • John Shue

    John Shue - 2024-03-11

    It appears to be the following line of code in SharpESI.ElectromagneticEmitter.NationalNomenclature.set() that is inserting the space:

    this.Root.Attribute("description").Value =
                string.IsNullOrEmpty(value) ? " " : value;
    

    Here's the full block of code:

        /// <summary>
        /// Gets or sets the national nomenclature
        /// </summary>
        public string NationalNomenclature
        {
          get
          {
            return this.Root.GetAttribute("description").Trim();
          }
    
          set
          {
            // Cannot use Root.SetAttribute(...) since the description attribute
            // is not optional (and thus we cannot remove the attribute if value
            // is empty
            if (this.Root.HasAttribute("description"))
            {
              this.Root.Attribute("description").Value =
                string.IsNullOrEmpty(value) ? " " : value;
            }
            else
            {
              XAttribute attribute = new XAttribute("description", value);
              this.Root.Add(attribute);
            }
          }
        }
    

    Here is the recommended replacement:

        /// <summary>
        /// Gets or sets the national nomenclature
        /// </summary>
        public string NationalNomenclature
        {
          get
          {
            return this.Root.GetAttribute("description").Trim();
          }
    
          set
          {
            // Cannot use Root.SetAttribute(...) since the description attribute
            // is not optional (and thus we cannot remove the attribute if value
            // is empty
            if (this.Root.HasAttribute("description"))
            {
              this.Root.Attribute("description").Value =
                string.IsNullOrEmpty(value) ? "" : value;
            }
            else
            {
              XAttribute attribute = new XAttribute("description", value);
              this.Root.Add(attribute);
            }
          }
        }
    
     
  • John Shue

    John Shue - 2024-09-11
    • status: new --> assigned
    • assigned_to: John Shue
    • Milestone: Not assigned --> v34
     

Log in to post a comment.