-
Notifications
You must be signed in to change notification settings - Fork 331
/
XmlSchemaExamples.shtml
168 lines (156 loc) · 5.21 KB
/
XmlSchemaExamples.shtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.17), see www.w3.org">
<title>JMRI: XML Schema Examples</title>
<meta name="author" content="Bob Jacobsen">
<meta name="keywords" content=
"JMRI technical code xml schema usage">
<!-- The combination of "Define" and {Header,Style, Logo and Footer} comments -->
<!-- are an arbitrary design pattern used by the update.pl script to -->
<!-- easily replace the common header/footer code for all the web pages -->
<!-- delete the following 2 Defines if you want to use the default JMRI logo -->
<!-- or change them to reflect your alternative logo -->
<!--#include virtual="/Style.shtml" -->
</head>
<body>
<!--#include virtual="/Header.shtml" -->
<div id="mBody">
<!--#include virtual="Sidebar.shtml" -->
<div id="mainContent">
<h1>JMRI Code: XML Schema Examples</h1>
<p>This page contains examples of various XML Schema fragments
that you might find useful.<br>
For discussion of JMRI's use of XML Schema, including info on
preferred patterns and organization, see <a href=
"XmlSchema.shtml">another page</a>.</p>
<h2>Element with just text content, no attributes</h2>
<pre>
<code>
<xs:element name="someData" minOccurs="0" maxOccurs="1">
</code>
</pre>That doesn't specify any typing. If you want e.g. to enforce
integer:
<pre>
<code>
<xs:element name="someIntThing" >
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:int" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
</code>
</pre>
<h2>Element with just attributes, no content</h2>Preferred
Venetion-blind form:
<pre>
<code>
<xs:element name="sample" type="SampleType"
minOccurs="0" maxOccurs="unbounded" />
<xs:complexType name="SampleType">
<xs:attribute name="foo" />
<xs:attribute name="bar" />
</xs:complexType>
</code>
</pre>Can also be combined if you think it's unlikely to be used
elsewhere:
<pre>
<code>
<xs:element name="sample"
minOccurs="0" maxOccurs="unbounded" />
<xs:complexType>
<xs:attribute name="foo" />
<xs:attribute name="bar" />
</xs:complexType>
</xs:element>
</code>
</pre>
<h2>Element with text content and attributes</h2>Restricting
the content of the element to just an integer:
<pre>
<code>
<xs:element name="someIntThing" >
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="someInt" type="xs:int"/>
<xs:attribute name="someText" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</code>
</pre>
<h2>Limiting an attribute to some specific values</h2>If you
want to do this, it's worth it to define a general type that
can be reused. These live in xml/schema/types/general.xsd.
<pre>
<code>
<xs:simpleType name="yesNoType">
<xs:annotation>
<xs:documentation>
General definition of string that's either "yes" or "no".
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
</code>
</pre>Then putting it on an attribute is simple:
<pre>
<code>
<xs:attribute name="opsOnly" type="yesNoType"/>
</code>
</pre>
<h2>Element with restricted text content</h2>Not an
attribute, an element:
<pre>
<code>
<xs:element name="relation">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ge"/>
<xs:enumeration value="lt"/>
<xs:enumeration value="eq"/>
<xs:enumeration value="ne"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</code>
</pre>
<h2>Attribute Groups</h2>Attribute Groups are good for
representing a set of attributes read and written together by
a common service routine. Example definition:
<pre>
<code>
<xs:attributeGroup name="EditorCommonAttributesGroup">
<xs:annotation>
<xs:documentation>
Define the XML stucture for storing common PositionableLabel child attributes
</xs:documentation>
<xs:appinfo>
jmri.jmrit.display.configurexml.PositionableLabelXml#storeCommonAttributes
</xs:appinfo>
</xs:annotation>
<xs:attribute name="x" type="xs:int" use="required" />
<xs:attribute name="y" type="xs:int" use="required" />
<xs:attribute name="level" type="xs:int" />
<xs:attribute name="forcecontroloff" type="trueFalseType" default="false" />
</xs:attributeGroup>
</code>
</pre>and example use in some later type:
<pre>
<code>
<xs:attributeGroup ref="EditorCommonAttributesGroup" />
</code>
</pre>
<!--#include virtual="/Footer.shtml" -->
</div><!-- closes #mainContent-->
</div><!-- closes #mBody-->
</body>
</html>