0
votes

I have an xml I want to validate against an xsd after adding a new attribute.
I tried to declare the attribute locally for some element in the xsd, but couldn't figure out how to do it.
On a whim, I took an already validated xml and added the new attribute to an element without any change to the xsd, and the validation passed successfully.

The attribute (letter-spacing) passed the validation only of it had a namespace prefix (namespace 'dptt' that is defined in the xsd and appears in the xml):
An example of a line that passed the validation:

<tt:style dptt:letter-spacing="4px" style="s01" tts:lineHeight="120px" xml:id="1"/>

An example of a line that didn't pass the validation:

<tt:style letter-spacing="4px" style="s01" tts:lineHeight="120px" xml:id="1"/>

This is the part of the xsd that defines the style attribute:

<xs:element name="style">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="tt:metadata" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute ref="xml:id" use="required">
        </xs:attribute>
        <xs:attribute name="style" type="xs:IDREFS">
        </xs:attribute>
        <xs:attribute ref="tts:direction" >
        </xs:attribute>
        <xs:attribute ref="tts:fontFamily" >
        </xs:attribute>
        <xs:attribute ref="tts:fontSize" >
        </xs:attribute>
        <xs:attribute ref="tts:lineHeight" >
        </xs:attribute>
        <xs:attribute ref="tts:textAlign" >
        </xs:attribute>
        <xs:attribute ref="tts:color" >
        </xs:attribute>
        <xs:attribute ref="tts:backgroundColor" >
        </xs:attribute>
        <xs:attribute ref="tts:fontStyle" >
        </xs:attribute>
        <xs:attribute ref="tts:fontWeight" >
        </xs:attribute>
        <xs:attribute ref="tts:textDecoration" >
        </xs:attribute>
        <xs:attribute ref="tts:unicodeBidi" >
        </xs:attribute>
        <xs:attribute ref="tts:padding">
        </xs:attribute>
        <xs:attribute ref="ebutts:multiRowAlign"/>
    </xs:complexType>
</xs:element>

I expect that an undeclared attribute won't pass the validation.
I also wonder why the addition of a namespace is crucial for validation.

2

2 Answers

2
votes

Without seeing the schema we can't possibly know. My guess would be that the complex type of the containing element included an xs:anyAttribute wildcard.

0
votes

Figured out that the schema referenced a different element than the one I thought it was referencing.
Took me a while to notice that the element from the xml

<tt:style letter-spacing="4px" style="s01" tts:lineHeight="120px" xml:id="1"/>

is not the same element from the xsd

<xs:element name="style">...</xs:element>

The tt:style element is defined somewhere else, and indeed contains a <xs:anyAttribute> element in one of the many referenced xsd.