I'm designing an XSD schema for all my XML I made after the fact. I know I should of done this first but I'm kinda new to it. So far all my XML works wonders for my app, I just want some good validation for it too.
Here is a quick example of what I'm going for.
<fields>
<field id="name" type="text">
<display>Somethings Name</display>
<description>The name of the something.</description>
</field>
</fields>
<forms>
<form id="custom_form">
<widgets>
<widget type="text-input">
<field id="name"/>
</widget>
</widgets>
</form>
</forms>
Here is a simplified example of the XSD I have:
<xs:sequence>
<xs:element name="fields" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="field" type="fieldType"
minOccurs="1" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="forms" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="form" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="widgets" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="widget" minOccurs="1" maxOccurs="unbounded">
<!-- What do I put here to reference a field? -->
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
My main question is how do I tell the XSD schema that the element within the widget
node is a reference to one of the fields defined in the fields
node above it? Right now I simply use code for this validation.
How should I define the field node in this scenario? Should I simply define the field
node twice, one for the main definition and one for referencing a field within a widget node?
I also saw there is the option to redefine nodes in an XSD as well. Should I maybe define the main field
definition then redefine it as a referenced style node for the widgets? How would I even do this?
Any suggestions for what is common or popular for this scenario?