Commit f99cc5cb authored by AS's avatar AS

New schema, including build tools for ant.

parent b6ec8466
<?xml version="1.0" encoding="UTF-8" ?>
<!-- - HGI Device Abstraction Layer - - - - - - - - - - - - - - - - - - - - -->
<!-- -->
<!-- Extends the standard build with targets for: -->
<!-- - generate XML schema the from Relax NG (xml) description -->
<!-- - validate DAL documents against the XML Schema -->
<!-- - generate HTML documentation from DAL documents -->
<project name="importing" basedir="." default="schemas">
<import file="../../etc/common.xml"/>
<!-- Read the namespace declarations from a file (to get linebreaks) - - - -->
<loadfile property="schema.xmlns" srcFile="${basedir}/etc/schema.xmlns"/>
<!-- The RNG file the XML and RNC schemas are generaed from - - - - - - - -->
<property name="schema.name" value="domain"/>
<property name="schema.rng" value="${path.src}/${schema.name}.rng"/>
<!-- HTML - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- -->
<!-- Generate HTML documentation from domain definitions in the test -->
<!-- directory. The module classes included via the extends tagged are -->
<!-- included in the documentation - so an xinclude capable XSL engine is -->
<!-- needed. -->
<!-- This needs Ant version 1.8+ and it must be augmented with an current -->
<!-- version of Xerces. Download the binray distribution and place the put -->
<!-- xml-apis.jar and xercesImpl.jar in the Ant lib directory. -->
<target name="html">
<xslt basedir="${basedir}/test" destdir="${basedir}/html"
style="${basedir}/style/html.xsl">
<param name="destdir" expression="${basedir}/html"/>
<sysproperty
key="org.apache.xerces.xni.parser.XMLParserConfiguration"
value="org.apache.xerces.parsers.XIncludeParserConfiguration"/>
</xslt>
</target>
<!-- Schemas - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- -->
<!-- The schema is specified using Relax NG (xml) and trang is used to -->
<!-- generate the XML schema. The schema is also generated in Relay NG -->
<!-- compact syntax, which is used by some validating editors (e.g. emacs) -->
<!-- The resulting schemas need some additional patching before thy are -->
<!-- usable -->
<target name="schemas">
<java jar="${basedir}/lib/trang.jar" fork="true">
<arg value="${schema.rng}"/>
<arg value="${basedir}/etc/${schema.name}.rnc"/>
</java>
<!-- So that the editor does not complain about include directives, the -->
<!-- resulting schema is included in another schema, which includes the -->
<!-- necessary element definitions. To be able to do this the -->
<!-- definition for Imports must be deleted from this generated schema. -->
<replace file="${basedir}/etc/${schema.name}.rnc"
token="Imports = element Imports { Domain* }?" value=""/>
<java jar="${basedir}/lib/trang.jar" fork="true">
<arg value="${schema.rng}"/>
<arg value="${path.src}/${schema.name}.xsd"/>
</java>
<!-- Can't validate against the generated schema unless we add the -->
<!-- target and default namespaces ... -->
<replace file='${path.src}/domain.xsd'
token='xmlns:xs="http://www.w3.org/2001/XMLSchema"'
value='${schema.xmlns}'/>
<!-- In addition the xml:base tag, which is added automatically when -->
<!-- including a document, must also be permitted by out schema. -->
<!-- The schema generated from RNG is almost correct schema ... but -->
<!-- the schemaLocation is wrong. -->
<replace file='${path.src}/domain.xsd'
token="xml.xsd" value="http://www.w3.org/2001/03/xml.xsd"/>
</target>
<!-- Validate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- -->
<!-- Check the Device Description conforms to the Device Abstraction -->
<!-- Schema. Note that we need to activate support for XML includes -->
<target name="validate" depends="">
<schemavalidate warn="true">
<fileset dir="${basedir}/test" includes="*.xml"/>
<attribute name="http://apache.org/xml/features/xinclude" value="true"/>
<schema namespace="http://hgi.org/xml/dal/1.0"
file="${path.src}/domain.xsd" />
<schema namespace="http://www.w3.org/2001/XInclude"
file="${basedir}/etc/XInclude.xsd" />
<schema namespace="http://www.w3.org/2001/XMLSchema"
file="${basedir}/etc/XMLSchema.xsd" />
</schemavalidate>
</target>
</project>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xi="http://www.w3.org/2001/XInclude"
targetNamespace="http://www.w3.org/2001/XInclude"
finalDefault="extension">
<xs:annotation>
<xs:documentation>
Not normative, but may be useful.
See the REC http://www.w3.org/TR/XInclude for definitive
information about this namespace.
</xs:documentation>
</xs:annotation>
<xs:element name="include" type="xi:includeType" />
<xs:complexType name="includeType" mixed="true">
<xs:choice minOccurs='0' maxOccurs='unbounded' >
<xs:element ref='xi:fallback' />
<xs:any namespace='##other' processContents='lax' />
<xs:any namespace='##local' processContents='lax' />
</xs:choice>
<xs:attribute name="href" use="optional" type="xs:anyURI"/>
<xs:attribute name="parse" use="optional" default="xml"
type="xi:parseType" />
<xs:attribute name="xpointer" use="optional" type="xs:string"/>
<xs:attribute name="encoding" use="optional" type="xs:string"/>
<xs:attribute name="accept" use="optional" type="xs:string"/>
<xs:attribute name="accept-language" use="optional" type="xs:string"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
<xs:simpleType name="parseType">
<xs:restriction base="xs:token">
<xs:enumeration value="xml"/>
<xs:enumeration value="text"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="fallback" type="xi:fallbackType" />
<xs:complexType name="fallbackType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="xi:include"/>
<xs:any namespace="##other" processContents="lax"/>
<xs:any namespace="##local" processContents="lax"/>
</xs:choice>
<xs:anyAttribute namespace="##other" processContents="lax" />
</xs:complexType>
</xs:schema>
<?xml version='1.0'?>
<!-- XML Schema schema for XML Schemas: Part 2: Datatypes -->
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" [
<!ENTITY % s ''>
<!ENTITY % p ''>
]>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema-datatypes"
version="$Id: XMLSchema-datatypes.xsd,v 1.5 2001/03/16 20:53:32 ht Exp $">
<annotation>
<documentation>Note this schema is NOT a normative schema - -
It contains types derived from all the builtin simple type definitions
with the same local name but in a distinct namespace, for use
by applications which do no wish to import the full XMLSchema
schema. Since derivation is not symmetric, unexpected results may
follow from mixing references to these definitions with references
to the definitions in the XMLSchema namespace. For example,
although dt:positiveInteger is derived from xs:integer, the converse
does not hold.</documentation>
</annotation>
<simpleType name="string">
<restriction base="string"/>
</simpleType>
<simpleType name="boolean">
<restriction base="boolean"/>
</simpleType>
<simpleType name="float">
<restriction base="float"/>
</simpleType>
<simpleType name="double">
<restriction base="double"/>
</simpleType>
<simpleType name="decimal">
<restriction base="decimal"/>
</simpleType>
<simpleType name="dateTime">
<restriction base="dateTime"/>
</simpleType>
<simpleType name="duration">
<restriction base="duration"/>
</simpleType>
<simpleType name="hexBinary">
<restriction base="hexBinary"/>
</simpleType>
<simpleType name="base64Binary">
<restriction base="base64Binary"/>
</simpleType>
<simpleType name="anyURI">
<restriction base="anyURI"/>
</simpleType>
<simpleType name="ID">
<restriction base="ID"/>
</simpleType>
<simpleType name="IDREF">
<restriction base="IDREF"/>
</simpleType>
<simpleType name="ENTITY">
<restriction base="ENTITY"/>
</simpleType>
<simpleType name="NOTATION">
<restriction base="NOTATION"/>
</simpleType>
<simpleType name="normalizedString">
<restriction base="normalizedString"/>
</simpleType>
<simpleType name="token">
<restriction base="token"/>
</simpleType>
<simpleType name="language">
<restriction base="language"/>
</simpleType>
<simpleType name="IDREFS">
<restriction base="IDREFS"/>
</simpleType>
<simpleType name="ENTITIES">
<restriction base="ENTITIES"/>
</simpleType>
<simpleType name="NMTOKEN">
<restriction base="NMTOKEN"/>
</simpleType>
<simpleType name="NMTOKENS">
<restriction base="NMTOKENS"/>
</simpleType>
<simpleType name="Name">
<restriction base="Name"/>
</simpleType>
<simpleType name="QName">
<restriction base="QName"/>
</simpleType>
<simpleType name="NCName">
<restriction base="NCName"/>
</simpleType>
<simpleType name="integer">
<restriction base="integer"/>
</simpleType>
<simpleType name="nonNegativeInteger">
<restriction base="nonNegativeInteger"/>
</simpleType>
<simpleType name="positiveInteger">
<restriction base="positiveInteger"/>
</simpleType>
<simpleType name="nonPositiveInteger">
<restriction base="nonPositiveInteger"/>
</simpleType>
<simpleType name="negativeInteger">
<restriction base="negativeInteger"/>
</simpleType>
<simpleType name="byte">
<restriction base="byte"/>
</simpleType>
<simpleType name="int">
<restriction base="int"/>
</simpleType>
<simpleType name="long">
<restriction base="long"/>
</simpleType>
<simpleType name="short">
<restriction base="short"/>
</simpleType>
<simpleType name="unsignedByte">
<restriction base="unsignedByte"/>
</simpleType>
<simpleType name="unsignedInt">
<restriction base="unsignedInt"/>
</simpleType>
<simpleType name="unsignedLong">
<restriction base="unsignedLong"/>
</simpleType>
<simpleType name="unsignedShort">
<restriction base="unsignedShort"/>
</simpleType>
<simpleType name="date">
<restriction base="date"/>
</simpleType>
<simpleType name="time">
<restriction base="time"/>
</simpleType>
<simpleType name="gYearMonth">
<restriction base="gYearMonth"/>
</simpleType>
<simpleType name="gYear">
<restriction base="gYear"/>
</simpleType>
<simpleType name="gMonthDay">
<restriction base="gMonthDay"/>
</simpleType>
<simpleType name="gDay">
<restriction base="gDay"/>
</simpleType>
<simpleType name="gMonth">
<restriction base="gMonth"/>
</simpleType>
</schema>
This diff is collapsed.
This diff is collapsed.
namespace local = ""
default namespace xsl = "http://hgi.org/xml/dal/1.0"
namespace xi = "http://www.w3.org/2001/XInclude"
version = "1.0"
include "domain.rnc"
xinclude = element xi:include {
attribute href { xsd:anyURI },
attribute parse { text }
}
Imports = element Imports { xinclude* }?
start = Domain
Domain =
element Domain {
# still having some problems with included documents ...
# the included document is given the attribute xml:base ...
# but my schema does not permit this ...
#
# This almost generates the correct schema ... but it
# doesn't have the correct schemaLocation
#
# <attribute ns="http://www.w3.org/XML/1998/namespace" name="base"> <data type="anyURI"/>
# </attribute>
attribute xml:base { xsd:anyURI }?,
attribute id { xsd:ID },
Imports,
element Modules {
element ModuleClass { ModuleDef }*
}?,
element Devices {
element Device {
attribute id { xsd:Name },
element DeviceInfo {
element Name { text }
& element Vendor { text }
},
Doc,
Modules?
}*
}?
}
DataType = "integer" | "boolean" | "string"
DocText =
(text
| element em { text }
| element b { text }
| element tt { text })*
Doc =
element Doc {
DocText
| (element p { DocText }
| element img {
attribute src { text },
element caption { text }
})*
}?
ModuleDef =
attribute name { text },
element extends {
attribute domain { xsd:IDREF },
attribute class { text }
}?,
Doc,
Actions?,
Data?,
Events?
Modules =
element Modules {
element Module { ModuleDef }*
}
Actions =
element Actions {
element Action {
attribute name { text },
attribute type { DataType }?,
Doc,
element Arg {
attribute name { text },
attribute type { DataType },
Doc
}*
}*
}
Data =
element Data {
element DataPoint {
attribute name { text },
attribute type { DataType }?,
attribute writable { xsd:boolean }?,
Doc
}*
}
Events =
element Events {
element Event {
attribute name { text }
}*
}
#
#
targetNamespace="http://hgi.org/xml/dal/1.0"
xmlns="http://hgi.org/xml/dal/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
\ No newline at end of file
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
<namespace ns="http://hgi.org/xml/dal/1.0" typeId="DAL"/>
<namespace ns="http://www.w3.org/2001/XInclude" typeId="XINC"/>
<typeId id="DAL" uri="dal.rnc"/>
<typeId id="XINC" uri="xinclude.rnc"/>
</locatingRules>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<ref name="Domain"/>
</start>
<define name="Imports">
<optional>
<element name="Imports">
<zeroOrMore>
<ref name="Domain"/>
</zeroOrMore>
</element>
</optional>
</define>
<define name="Domain">
<element name="Domain">
<optional>
<!-- still having some problems with included documents ...
the included document is given the attribute xml:base ...
but my schema does not permit this ...
This almost generates the correct schema ... but it
doesn't have the correct schemaLocation
<attribute ns="http://www.w3.org/XML/1998/namespace" name="base"> <data type="anyURI"/>
</attribute>
-->
<attribute name="xml:base">
<data type="anyURI"/>
</attribute>
</optional>
<attribute name="id">
<data type="ID"/>
</attribute>
<ref name="Imports"/>
<optional>
<element name="Modules">
<zeroOrMore>
<element name="ModuleClass">
<ref name="ModuleDef"/>
</element>
</zeroOrMore>
</element>
</optional>
<optional>
<element name="Devices">
<zeroOrMore>
<element name="Device">
<attribute name="id">
<data type="Name"/>
</attribute>
<element name="DeviceInfo">
<interleave>
<element name="Name">
<text/>
</element>
<element name="Vendor">
<text/>
</element>
</interleave>
</element>
<ref name="Doc"/>
<optional>
<ref name="Modules"/>
</optional>
</element>
</zeroOrMore>
</element>
</optional>
</element>
</define>
<define name="DataType">
<choice>
<value>integer</value>
<value>boolean</value>
<value>string</value>
</choice>
</define>
<define name="DocText">
<zeroOrMore>
<choice>
<text/>
<element name="em">
<text/>
</element>
<element name="b">
<text/>
</element>
<element name="tt">
<text/>
</element>
</choice>
</zeroOrMore>
</define>
<define name="Doc">
<optional>
<element name="Doc">
<choice>
<ref name="DocText"/>
<zeroOrMore>
<choice>
<element name="p">
<ref name="DocText"/>
</element>
<element name="img">
<attribute name="src"/>
<element name="caption">
<text/>
</element>
</element>
</choice>
</zeroOrMore>
</choice>
</element>
</optional>
</define>
<define name="ModuleDef">
<attribute name="name">
<text/>
</attribute>
<optional>
<element name="extends">
<attribute name="domain">
<data type="IDREF"/>
</attribute>
<attribute name="class"/>
</element>
</optional>
<ref name="Doc"/>
<optional>
<ref name="Actions"/>
</optional>
<optional>
<ref name="Data"/>
</optional>
<optional>
<ref name="Events"/>
</optional>
</define>
<define name="Modules">
<element name="Modules">
<zeroOrMore>
<element name="Module">
<ref name="ModuleDef"/>
</element>
</zeroOrMore>
</element>
</define>
<define name="Actions">
<element name="Actions">
<zeroOrMore>
<element name="Action">
<attribute name="name">
<text/>
</attribute>
<optional>
<attribute name="type">
<ref name="DataType"/>
</attribute>
</optional>
<ref name="Doc"/>
<zeroOrMore>
<element name="Arg">
<attribute name="name"/>
<attribute name="type">
<ref name="DataType"/>
</attribute>
<ref name="Doc"/>
</element>
</zeroOrMore>
</element>
</zeroOrMore>
</element>
</define>
<define name="Data">
<element name="Data">
<zeroOrMore>
<element name="DataPoint">
<attribute name="name">
<text/>
</attribute>
<optional>
<attribute name="type">
<ref name="DataType"/>
</attribute>
</optional>
<optional>
<attribute name="writable">
<data type="boolean"/>
</attribute>
</optional>
<ref name="Doc"/>
</element>
</zeroOrMore>
</element>
</define>
<define name="Events">
<element name="Events">
<zeroOrMore>
<element name="Event">
<attribute name="name">
<text/>
</attribute>
</element>
</zeroOrMore>
</element>
</define>
<!-- -->
<!-- -->
</grammar>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://hgi.org/xml/dal/1.0"
xmlns="http://hgi.org/xml/dal/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
<xs:group name="Imports">
<xs:sequence>
<xs:element minOccurs="0" ref="Imports"/>
</xs:sequence>
</xs:group>
<xs:element name="Imports">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="Domain"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Domain">
<xs:complexType>
<xs:sequence>
<xs:group ref="Imports"/>
<xs:element minOccurs="0" name="Modules">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="ModuleClass"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" ref="Devices"/>
</xs:sequence>
<xs:attribute ref="xml:base"/>
<xs:attribute name="id" use="required" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="ModuleClass" type="ModuleDef"/>
<xs:element name="Devices">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="Device"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Device">
<xs:complexType>
<xs:sequence>
<xs:element ref="DeviceInfo"/>
<xs:group ref="Doc"/>
<xs:element minOccurs="0" ref="Modules"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:Name"/>
</xs:complexType>
</xs:element>
<xs:element name="DeviceInfo">
<xs:complexType>
<xs:all>
<xs:element ref="Name"/>
<xs:element ref="Vendor"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Vendor" type="xs:string"/>
<xs:simpleType name="DataType">
<xs:restriction base="xs:token">
<xs:enumeration value="integer"/>
<xs:enumeration value="boolean"/>
<xs:enumeration value="string"/>
</xs:restriction>
</xs:simpleType>
<xs:group name="DocText">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="em"/>
<xs:element ref="b"/>
<xs:element ref="tt"/>
</xs:choice>
</xs:sequence>
</xs:group>
<xs:element name="em" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="tt" type="xs:string"/>
<xs:group name="Doc">
<xs:sequence>
<xs:element minOccurs="0" ref="Doc"/>
</xs:sequence>