Uploaded image for project: 'Daffodil'
  1. Daffodil
  2. DAFFODIL-2481

newVariableInstance does not use external values when defaultValue is not defined

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.1.0
    • None
    • None

    Description

      Regarding newVariableInstance and defaultValue, the spec says:

      If the instance is not assigned a new default value then it inherits the default value specified by dfdl:defineVariable or externally provided by the DFDL processor.

      Daffodil does not support the "or externally provided" part of this. If NVI does not provide a defaultValue, then we always use the defaultValue specified by the defineVariable, regardless if it was set externally.

      For example, say we have this schema:

        <xs:annotation>
          <xs:appinfo source="http://www.ogf.org/dfdl/">
            <dfdl:format ref="ex:GeneralFormat" />
            <dfdl:defineVariable name="var1" type="xs:int" defaultValue="1" external="true" />
          </xs:appinfo>
        </xs:annotation>
      
        <xs:element name="root">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="beforeNVI" type="xs:int" dfdl:inputValueCalc="{ $ex:var1 }" />
              <xs:sequence>
                <xs:annotation>
                  <xs:appinfo source="http://www.ogf.org/dfdl/">
                    <dfdl:newVariableInstance ref="ex:var1" />
                  </xs:appinfo>
                </xs:annotation>
                <xs:element name="afterNVI" type="xs:int" dfdl:inputValueCalc="{ $ex:var1 }" />
              </xs:sequence>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      

      So the "var1" variable defaults to "1", and newVariableInstance does not provide a default value.

      If we run the following to parse with an externally set value of 2:

      daffodil parse -Dvar1=2 ...
      

      Then we get the resulitng infoset:

      <root>
        <beforeNVI>2</beforeNVI>
        <afterNVI>1</afterNVI>
      </root>
      

      Which isn't correct. Because var1 was set externally to 2, the NVI should use that value as the default, so both beforeNVI and afterNVI should have a value of 2.

      Attachments

        Activity

          People

            Unassigned Unassigned
            slawrence Steve Lawrence
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: