Search code examples
xmlxsdxsd-1.1

Add annotation-documentation to XSD child element


I want to add an annotation-documentation to a XSD child element:

For example:

<xsd:complexType name="XY">
    <xsd:sequence>
        <xsd:element type="xType" name="x"/>
            <xsd:annotation>
                <xsd:documentation> I want to add a description here. 
                </xsd:documentation>
            </xsd:annotation>
        <xsd:element type="yType" name="y"/>
    </xsd:sequence>
    <xsd:attribute type="xsd:string" name="NAME" use="required"/>
</xsd:complexType>

does obviously not work.

Is there a way to explicitly define a documentation of just the child element


Solution

  • Don't tell us it doesn't work, tell us how it fails!

    I can't see any reason your code should fail (let alone any "obvious" reason). Of course, it contains references to undeclared types. The following example works just fine:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        
        <xs:element name="X">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="a" type="xs:string">
                        <xs:annotation>
                            <xs:documentation>Great!</xs:documentation>
                        </xs:annotation>
                    </xs:element>
                </xs:sequence>
                <xs:assert test="matches(a, '^(hello|world)$', 'm')"/>                                           
            </xs:complexType>
        </xs:element>
        
    </xs:schema>