158 lines
4.8 KiB
Plaintext
158 lines
4.8 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy for HTML5 for Apple macOS version 5.8.0">
|
|
<title>JMRI: XML Schema Examples</title>
|
|
<meta name="author" content="Bob Jacobsen">
|
|
<meta name="keywords" content="JMRI technical code xml schema usage">
|
|
<!--#include virtual="/help/en/parts/Style.shtml" -->
|
|
</head>
|
|
<body>
|
|
<!--#include virtual="/help/en/parts/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>
|
|
|
|
<code class="block">
|
|
<xs:element name="someData" minOccurs="0" maxOccurs="1">
|
|
</code>
|
|
That doesn't specify any typing. If you want e.g. to enforce integer:
|
|
|
|
<code class="block">
|
|
<xs:element name="someIntThing" >
|
|
<xs:complexType>
|
|
<xs:simpleContent>
|
|
<xs:extension base="xs:int" />
|
|
</xs:simpleContent>
|
|
</xs:complexType>
|
|
</xs:element>
|
|
</code>
|
|
|
|
<h2>Element with just attributes, no content</h2>
|
|
Preferred Venetion-blind form:
|
|
|
|
<code class="block">
|
|
<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>
|
|
|
|
Can also be combined if you think it's unlikely to be used elsewhere:
|
|
|
|
<code class="block">
|
|
<xs:element name="sample"
|
|
minOccurs="0" maxOccurs="unbounded" />
|
|
<xs:complexType>
|
|
<xs:attribute name="foo" />
|
|
<xs:attribute name="bar" />
|
|
</xs:complexType>
|
|
</xs:element>
|
|
</code>
|
|
|
|
<h2>Element with text content and attributes</h2>
|
|
Restricting the content of the element to just an integer:
|
|
|
|
<code class="block">
|
|
<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>
|
|
|
|
<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.
|
|
|
|
<code class="block">
|
|
<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>
|
|
|
|
Then putting it on an attribute is simple:
|
|
|
|
<code class="block">
|
|
<xs:attribute name="opsOnly" type="yesNoType"/>
|
|
</code>
|
|
|
|
<h2>Element with restricted text content</h2>
|
|
Not an attribute, an element:
|
|
|
|
<code class="block">
|
|
<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>
|
|
|
|
<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:
|
|
|
|
<code class="block">
|
|
<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>
|
|
|
|
and example use in some later type:
|
|
|
|
|
|
<code class="block">
|
|
<xs:attributeGroup ref="EditorCommonAttributesGroup" />
|
|
</code>
|
|
|
|
<!--#include virtual="/help/en/parts/Footer.shtml" -->
|
|
</div>
|
|
<!-- closes #mainContent-->
|
|
</div>
|
|
<!-- closes #mBody-->
|
|
<script src="/js/help.js"></script>
|
|
</body>
|
|
</html>
|