Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator reports constraint exceeded for gradientFill stop #25

Closed
Themanwithoutaplan opened this issue Jan 12, 2015 · 2 comments
Closed

Comments

@Themanwithoutaplan
Copy link

The validator reports an error for the following style definition:

  <x:fill>
    <x:gradientFill type="linear" degree="90">
      <x:stop position="0">
        <x:color theme="0" />
      </x:stop>
      <x:stop position="1">
        <x:color theme="4" />
      </x:stop>
      <x:stop position="2">
        <x:color rgb="00FF0000" />
      </x:stop>
    </x:gradientFill>
  </x:fill>

I can't find the matching constraint. This is specification for a gradientFill:

<xsd:complexType name="CT_GradientFill">
    <xsd:sequence>
       <xsd:element name="stop" type="CT_GradientStop" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="type" type="ST_GradientType" use="optional" default="linear"/>
    <xsd:attribute name="degree" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="left" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="right" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="top" type="xsd:double" use="optional" default="0"/>
    <xsd:attribute name="bottom" type="xsd:double" use="optional" default="0"/>
</xsd:complexType>
<xsd:complexType name="CT_GradientStop">
    <xsd:sequence>
       <xsd:element name="color" type="CT_Color" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
    <xsd:attribute name="position" type="xsd:double" use="required"/>
</xsd:complexType>

If I understand this correctly then there can be an unlimited number of stops. Any limits could be imposed using the maxOccurs attribute of the fill.

@twsouthwick
Copy link
Member

@tomjebo Can you take a look at this?

@twsouthwick
Copy link
Member

Here's a repro:

            var xml = @"  <x:fill xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
    <x:gradientFill type=""linear"" degree=""90"">
      <x:stop position=""0"">
        <x:color theme=""0"" />
      </x:stop>
      <x:stop position=""1"">
        <x:color theme=""4"" />
      </x:stop>
      <x:stop position=""2"">
        <x:color rgb=""00FF0000"" />
      </x:stop>
    </x:gradientFill>
  </x:fill>";
            var fill = new Fill(xml);

            var validator = new OpenXmlValidator();
            var results = validator.Validate(fill);

            Assert.Empty(results);

I get the following error:

Description="The attribute 'position' has invalid value '2'. The MaxInclusive constraint failed. The value must be less than or equal to 1."

The semantic validation (not in the schema) constrains the value of position between 0 and 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants