Creating a Simple Schema
As a simple example to get you started building schemas, examine the structure of Example C-1. You may have seen the document before (it was Example A-1 in Appendix A), but this time do an inventory of the parts it contains.
Example C-1. A simple XML document for definition in a schema
<?xml version="1.0" encoding="us-ascii"?>
<authors>
<person id="lear">
<name>Edward Lear</name>
<nationality>British</nationality>
</person>
<person id="asimov">
<name>Isaac Asimov</name>
<nationality>American</nationality>
</person>
<person id="mysteryperson"/>
</authors>This document contains an authors element, which
itself contains multiple person elements. Each
person element has an id
attribute and may contain a name and a
nationality element. For now,
we’ll treat all of the textual content of the
elements and attributes as text. One way to define this document in a
schema is with a schema whose structure mirrors the document shown in
Example C-2, called a “Russian
doll” schema after the wooden
matruschkas. The names of the elements being
defined are in bold to make it easier to read.
Example C-2. A “russian doll” schema that describes Example C-1.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="authors"> <xs:complexType> <xs:sequence> <xs:element name="person" maxOccurs="unbounded"> <xs:complexType> <xs:sequence minOccurs="0" > <xs:element name="name" type="xs:string" /> <xs:element name="nationality" type="xs:string" /> </xs:sequence> <xs:attribute ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access