Wednesday, December 30, 2009

The Schema file for my FAQ

Here is my .xsd file.

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

This is where I define the faq element. This is my "root" element. It has two attributes which I use to store version information (version, and editDate). It contains a series of sections.

<xs:element name="faq">
<xs:complexType>
<xs:sequence>
<xs:element ref="section" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required" />
<xs:attribute name="editDate" type="xs:string" use="required" />
</xs:complexType>
</xs:element>


This where I define the item element (I need to change the item and section definitions)
Each item contains an id, a question, an answer, and possibly multiple "see also" links.

<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="question" maxOccurs="1" />
<xs:element ref="answer" maxOccurs="1" />
<xs:element ref="see" minOccurs="0" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
</xs:complexType>
</xs:element>

Each section contains multiple items as well as a title.

<xs:element name="section">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="title" type="xs:string" use="required" />
</xs:complexType>
</xs:element>

Each question is a plain string of text.
I had to resort to a weird trick for answers (to allow HTML) so I defined them as a mixed type.

<!-- describe things in a section -->
<xs:element name="question" type="xs:string" />

<xs:element name="answer">
<xs:complexType mixed="true" />
</xs:element>

Each see element gets converted to the text "see also ..." with a link to the question. The section id, question id are attributes of the see element.

<xs:element name="see">
<xs:complexType mixed="true">
<xs:attribute name="question" type="xs:NMTOKEN" use="required" />
<xs:attribute name="section" type="xs:NMTOKEN" use="required" />
</xs:complexType>
</xs:element>

</xs:schema>

No comments:

Post a Comment

Have something you want to say? You think I'm wrong? Found something I said useful?
Leave a comment!