2

I'm tasked with validating and interpreting and XSD Schema, this schema starts with:

<xsd:schema xmlns:xsd="http://....">
<xsd:complexType name="TemplateType"> <!-- Nowhere referenced -->
  <xsd:sequence>
    <xsd:element name="DataType" type="DocumentDataType"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DocumentDataType">

It's been too long since my last XSD task, but somewhere I would expect a <element type="templateType">, but this is not the case.

What is wrong here? My rusty XSD knowledge or the delivered XSD?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
dr jerry
  • 9,768
  • 24
  • 79
  • 122
  • In your xsd:schema tag you most probably reference a schema which contains the definitions for complexType, sequence etc (i.e. http://www.w3.org/2001/XMLSchema). Then you can use those types and define your own XML elements, like TemplateType, DataType etc. – M. F. Mar 02 '18 at 13:37
  • You can also play with this on-line validator to help you in your XSD-related tasks: http://www.utilities-online.info/xsdvalidation/#.WplSI4Khcy4 – M. F. Mar 02 '18 at 13:39

1 Answers1

2

A complex type name (xsd:complexType/@name) could be

  1. Used to define the type of an element (xsd:element/@type), as you say.
  2. Used to define derived types via extension (xsd:extension/@base) or restriction (xsd:restriction/@base).
  3. Used in XSDs that include or import this XSD.
  4. Used in XML instances via xsi:type. [Credit @MichaelKay]
  5. Planned for future use in the current XSD.
  6. Simply be unused.

So, your TemplateType may serve another purpose besides the direct definition of an element type, or it may have become vestigial over the course of the evolution of the XSD.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • It could also be referenced using `@xsi:type` in an instance document. There are some vocabularies/frameworks such as Fpml that make heavy use of `@xsi:type` in this way. – Michael Kay Mar 02 '18 at 17:37
  • @MichaelKay: Ah, I forgot about `@xsi:type`; good point. Answer updated. Thank you! – kjhughes Mar 02 '18 at 17:48