Nifty XSD

A question in advance: Can a layer have a position and dimension or is it always like the screen? What I’ve read about it is a bit inconsistent. Giving it a width and height seems to have no effect in jME3.



The second thing: The (Nifty) XML-Editor with code completion is really nice. Unfortunately, it doesn’t work with Nifty. I think the problem is the Nifty XSD. In my opinion, “substitutionGroup” is used where “xs:choice” has to be used and it’s not clearly defined which element can contain what. I think it’s not possible to define the structure just using types (XSD flaw). It has to be defined by elements. I spent a lot of time with XML and XSD at work and had a lot of pain. So I just provide this example how it can be done and hope it helps. Put bothfiles into the same directory, drag DeviceStructure.xml into jME3 Platform and hit CTRL-SPACE below the comment to see how it works. Please note that the xml bbcode has problems with URIs so I put in some spaces.



DeviceStructure.xml

[xml]

<?xml version=“1.0” encoding=“utf-8”?>

<deviceStructure

xmlns:xsi=“h t t p : / / w w w . w 3 . o r g/2001/XMLSchema-instance”

xsi:noNamespaceSchemaLocation=“DeviceStructure.xsd”

defaultValuesCrc=“deadbeef” parametersCrc=“feedaffe”

>

<safeDataStructure>

<!–

Put DeviceStructure.xsd and DeviceStructure.xml into the same directory,

drag DeviceStructure.xml (this file) into jME3 Platform and

hit CTRL-SPACE below this comment.

–>

</safeDataStructure>

</deviceStructure>

[/xml]



DeviceStructure.xsd

[xml]

<?xml version=“1.0” encoding=“UTF-8”?>

<xs:schema

xmlns:xs=“XML Schema

elementFormDefault=“qualified”

attributeFormDefault=“unqualified”

>

<!-- BEGIN: Wurzelelement (root element) -->

<xs:element name=“deviceStructure” type=“DeviceStructure”>

<xs:annotation>

<xs:documentation>Das Wurzelelement vom Typ DeviceStructure.</xs:documentation>

</xs:annotation>



<!-- BEGIN: Beschränkungen (constraints) -->

<xs:key name=“parameterKeyLocal”>

<xs:annotation>

<xs:documentation>‘parameterGroups/parameterGroup/parameterReference@idRef’ muss auf ‘safeDataStructure/parameter@id’ verweisen.</xs:documentation>

</xs:annotation>

<xs:selector xpath=“safeDataStructure/rangeParameter |

safeDataStructure/signedRangeParameter |

safeDataStructure/floatParameter |

safeDataStructure/doubleParameter |

safeDataStructure/enumParameter”/>

<xs:field xpath="@id"/>

</xs:key>

<xs:keyref name=“parameterKeyRefLocal” refer=“parameterKeyLocal”>

<xs:annotation>

<xs:documentation>‘parameterGroups/parameterGroup/parameterReference@idRef’ muss auf ‘safeDataStructure/parameter@id’ verweisen.</xs:documentation>

</xs:annotation>

<xs:selector xpath=“parameterGroups/parameterGroup/parameterReference”/>

<xs:field xpath="@idRef"/>

</xs:keyref>



<xs:unique name=“parameterIdRefUniqueLocal”>

<xs:annotation>

<xs:documentation>‘parameterGroups/parameterGroup/parameterReference@idRef’ muss eindeutig sein.</xs:documentation>

</xs:annotation>

<xs:selector xpath=“parameterGroups/parameterGroup/parameterReference”/>

<xs:field xpath="@idRef"/>

</xs:unique>

<!-- END: Beschränkungen (constraints) -->

</xs:element>

<!-- END: Wurzelelement (root element) -->



<!-- BEGIN: Typdefinitionen (type definitions) -->

<xs:complexType name=“DeviceStructure”>

<xs:annotation>

<xs:documentation>Typdefinition von DeviceStructure.</xs:documentation>

</xs:annotation>

<xs:sequence>

<!–

<xs:element ref=“DeviceInformation”/>

<xs:element ref=“PlausibilityCheck” minOccurs=“0”/>

–>

<xs:element name=“safeDataStructure” type=“SafeDataStructure” minOccurs=“1” maxOccurs=“1”/>

<xs:element name=“parameterGroups” type=“ParameterGroups” minOccurs=“1” maxOccurs=“1”/>

</xs:sequence>



<xs:attribute name=“defaultValuesCrc” type=“xs:hexBinary” use=“required”/>

<xs:attribute name=“parametersCrc” type=“xs:hexBinary” use=“required”/>

<!–

<xs:attribute name=“startCrcOffset” type=“xs:unsignedInt” use=“required” fixed=“4”/>

<xs:attribute name=“numOfBytesForCrc” type=“xs:unsignedInt” use=“required” fixed=“4”/>

–>

</xs:complexType>



<xs:complexType name=“SafeData”>

<xs:annotation>

<xs:documentation>SafeData ist der Basistyp für sichere Daten.</xs:documentation>

</xs:annotation>



<xs:attribute name=“id” type=“xs:NCName” use=“required”/>

<xs:attribute name=“bitLength” type=“BitLength” use=“required”/>

</xs:complexType>



<xs:complexType name=“SafeDataReference”>

<xs:annotation>

<xs:documentation>Eine SafeData-Referenz.</xs:documentation>

</xs:annotation>



<xs:attribute name=“idRef” type=“xs:NCName” use=“required”/>

</xs:complexType>



<xs:complexType name=“SafeDataStructure”>

<xs:annotation>

<xs:documentation>Enthält die Struktur der sicheren Daten, wie sie in der Binärdatei landen.</xs:documentation>

</xs:annotation>



<xs:sequence minOccurs=“0” maxOccurs=“unbounded”>

<xs:choice>

<xs:element name=“rangeParameter” type=“RangeParameter” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Ein vorzeichenlose Dezimalzahl mit variable Bitlänge (bis zu 32 Bit).</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name=“signedRangeParameter” type=“SignedRangeParameter” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Ein vorzeichenbehaftete Dezimalzahl (32 Bit).</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name=“floatParameter” type=“FloatParameter” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Ein Fließkommazahl mit einfacher Genauigkeit (32 Bit).</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name=“doubleParameter” type=“DoubleParameter” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Ein Fließkommazahl mit doppelter Genauigkeit (64 Bit).</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name=“enumParameter” type=“EnumParameter” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Ein frei definierbarer Aufzählungstyp mit variabler Bitlänge (bis zu 32 Bit).</xs:documentation>

</xs:annotation>

<!-- EnumParameter@defaultValueRef -> EnumEntry@value -->

<xs:key name=“enumValueKey”>

<xs:annotation>

<xs:documentation>EnumParameter@defaultValueRef -> EnumEntry@value</xs:documentation>

</xs:annotation>

<xs:selector xpath=“enumEntry”/>

<xs:field xpath="@value"/>

</xs:key>

<xs:keyref name=“enumDefaultValueKeyRef” refer=“enumValueKey”>

<xs:annotation>

<xs:documentation>EnumParameter@defaultValueRef -> EnumEntry@value</xs:documentation>

</xs:annotation>

<xs:selector xpath="."/>

<xs:field xpath="@defaultValueRef"/>

</xs:keyref>

</xs:element>

<xs:element name=“bitstream” type=“Bitstream” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>Eine Bitfolge mit frei definierbarer Bitlänge.

Ein Bitstream der Länge 32 an Position 0 wird mit der CRC über die Datenstruktur gefüllt.

Kann auch für Konstanten und Zeichenketten verwendet werden, die an das Gerät übermittelt werden sollen.

Auch als Füll-Bits auf Byte-Grenzen zu verwenden.

</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name=“metaBitstream” type=“MetaBitstream” minOccurs=“0” maxOccurs=“unbounded”>

<xs:annotation>

<xs:documentation>

MetaBitstreams sind als eine Möglichkeit gedacht, Anwendungsparameter auf dem Gerät zu speichern.

Sie gehen nicht mit in die CRC-Prüfung ein.

</xs:documentation>

</xs:annotation>

</xs:element>

</xs:choice>

</xs:sequence>

</xs:complexType>



<xs:simpleType name=“ExtendedType”>

<xs:restriction base=“xs:NCName”>

<xs:enumeration id=“STANDARD” value=“STANDARD”/>

<xs:enumeration id=“ADVANCED” value=“ADVANCED”/>

<xs:enumeration id=“COMMISSIONING” value=“COMMISSIONING”/>

</xs:restriction>

</xs:simpleType>



<xs:simpleType name=“BitLength”>

<xs:restriction base=“xs:unsignedInt”>

<xs:minInclusive value=“1”/>

</xs:restriction>

</xs:simpleType>



<xs:simpleType name=“BitLength32”>

<xs:restriction base=“BitLength”>

<xs:minInclusive value=“1”/>

<xs:maxInclusive value=“32”/>

</xs:restriction>

</xs:simpleType>



<xs:complexType name=“Parameter” abstract=“true”>

<xs:annotation>

<xs:documentation>Parameter (abgeleitet von SafeData) ist der Basistyp

für alle Parameter.</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“SafeData”>

<xs:attribute name=“labelIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“descriptionIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“unitIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“extendedType” type=“ExtendedType” default=“STANDARD”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“DynamicBitlength32Parameter” abstract=“true”>

<xs:annotation>

<xs:documentation>

DynamicBitlength32Parameter (abgeleitet von Parameter) ist der abstrakte Basistyp

für ganzzahlige Parameter ohne Vorzeichen mit variabler Bitlänge (bis zu 32 Bit).

</xs:documentation>

</xs:annotation>

<xs:complexContent>

<xs:restriction base=“Parameter”>

<xs:attribute name=“bitLength” type=“BitLength32” use=“required”/>

</xs:restriction>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“RangeParameter”>

<xs:annotation>

<xs:documentation>

RangeParameter (abgeleitet von DynamicBitlength32Parameter) ist der Basistyp

für ganzzahlige Parameter ohne Vorzeichen mit variabler Bitlänge (bis zu 32 Bit).</xs:documentation>

</xs:annotation>

<xs:complexContent>

<xs:extension base=“DynamicBitlength32Parameter”>

<xs:attribute name=“defaultValue” type=“xs:unsignedInt” use=“required”/>

<xs:attribute name=“minValue” type=“xs:unsignedInt” use=“required”/>

<xs:attribute name=“maxValue” type=“xs:unsignedInt” use=“required”/>

<xs:attribute name=“stepSize” type=“xs:unsignedInt” use=“required”/>

<xs:attribute name=“bitLength” type=“BitLength32” default=“32”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“SignedRangeParameter”>

<xs:annotation>

<xs:documentation>

SignedRangeParameter (abgeleitet von Parameter) ist der Basistyp

für ganzzahlige Parameter mit Vorzeichen.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“Parameter”>

<xs:attribute name=“defaultValue” type=“xs:int” use=“required”/>

<xs:attribute name=“minValue” type=“xs:int” use=“required”/>

<xs:attribute name=“maxValue” type=“xs:int” use=“required”/>

<xs:attribute name=“stepSize” type=“xs:int” use=“required”/>

<xs:attribute name=“bitLength” type=“BitLength” fixed=“32”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“FloatParameter”>

<xs:annotation>

<xs:documentation>

FloatParameter (abgeleitet von Parameter) ist der Basistyp

für Fließkomma-Parameter mit einfacher Genauigkeit.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“Parameter”>

<xs:attribute name=“defaultValue” type=“xs:float” use=“required”/>

<xs:attribute name=“minValue” type=“xs:float” use=“required”/>

<xs:attribute name=“maxValue” type=“xs:float” use=“required”/>

<xs:attribute name=“bitLength” type=“BitLength” fixed=“32”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“DoubleParameter”>

<xs:annotation>

<xs:documentation>

DoubleParameter (abgeleitet von Parameter) ist der Basistyp

für Fließkomma-Parameter mit doppelter Genauigkeit.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“Parameter”>

<xs:attribute name=“defaultValue” type=“xs:double” use=“required”/>

<xs:attribute name=“minValue” type=“xs:double” use=“required”/>

<xs:attribute name=“maxValue” type=“xs:double” use=“required”/>

<xs:attribute name=“bitLength” type=“BitLength” fixed=“64”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“EnumEntry”>

<xs:annotation>

<xs:documentation>

EnumEntry repräsentiert einen einzelnen Wert von EnumParameter.

</xs:documentation>

</xs:annotation>



<xs:sequence>

<xs:element name=“enableParameter” type=“SafeDataReference” minOccurs=“0” maxOccurs=“unbounded”/>

<xs:element name=“disableParameter” type=“SafeDataReference” minOccurs=“0” maxOccurs=“unbounded”/>

</xs:sequence>



<xs:attribute name=“labelIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“value” type=“xs:unsignedInt” use=“required”/>

</xs:complexType>



<xs:complexType name=“EnumParameter”>

<xs:annotation>

<xs:documentation>

EnumParameter (abgeleitet von Parameter) ist der Basistyp

für Aufzählungstyp-Parameter.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“DynamicBitlength32Parameter”>

<xs:sequence>

<xs:element name=“enumEntry” type=“EnumEntry” minOccurs=“2” maxOccurs=“unbounded”>

<xs:unique name=“enumEntryEnableDisableUnique”>

<xs:selector xpath=“enableParameter | disableParameter”/>

<xs:field xpath="@idRef"/>

</xs:unique>

</xs:element>

</xs:sequence>

<xs:attribute name=“defaultValueRef” type=“xs:unsignedInt” use=“required”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“AbstractBitstream” abstract=“true”>

<xs:annotation>

<xs:documentation>

AbstractBitstream (abgeleitet von SafeData) ist der Basistyp

für alle Bitstreams und MetaBitstreams.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“SafeData”>

<xs:attribute name=“data” type=“xs:hexBinary” use=“required”/>

</xs:extension>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“Bitstream”>

<xs:annotation>

<xs:documentation>

Bitstream (abgeleitet von AbstractBitstream) ist der Typ

für alle Bitstreams.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“AbstractBitstream”/>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“MetaBitstream”>

<xs:annotation>

<xs:documentation>

MetaBitstream (abgeleitet von AbstractBitstream) ist der Typ

für alle MetaBitstreams.

</xs:documentation>

</xs:annotation>



<xs:complexContent>

<xs:extension base=“AbstractBitstream”/>

</xs:complexContent>

</xs:complexType>



<xs:complexType name=“ParameterGroup”>

<xs:annotation>

<xs:documentation>Eine Gruppe von Referenzen auf Parameter.</xs:documentation>

</xs:annotation>



<xs:sequence maxOccurs=“unbounded”>

<xs:element name=“parameterReference” type=“SafeDataReference” minOccurs=“1”/>

</xs:sequence>



<xs:attribute name=“labelIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“pictureFileIdRef” type=“xs:NCName” use=“required”/>

<xs:attribute name=“extendedType” type=“ExtendedType” default=“STANDARD”/>

</xs:complexType>



<xs:complexType name=“ParameterGroups”>

<xs:annotation>

<xs:documentation>Eine Liste von ParameterGroups.</xs:documentation>

</xs:annotation>



<xs:sequence>

<xs:element name=“parameterGroup” type=“ParameterGroup” minOccurs=“1” maxOccurs=“unbounded”/>

</xs:sequence>

</xs:complexType>

<!-- END: Typdefinitionen (type definitions) -->

</xs:schema>

[/xml]

First question:



Yes, a layer is always screen size and you can’t change its size. A layer is just that, a layer that is used to group and organize elements. Not being able to change the layer size shouldn’t matter at all because by default it’s invisible to the mouse and there is nothing there that would get rendered for an empty layer.



Second question:



I don’t understand the XSD you’ve posted at all. It seems to not have any relation to Nifty, right?



Ok, might be a side effect of my cold but doesn’t make sense :smiley:

The XSD has no relation to Nifty. It’s just an example. I was too lazy to translate the Nifty XSD to the “dialect” used above. It’s been a while since I messed around with XSD, so you might have good reasons doing it the way you do it.



Edit: I looked a bit more into your XSD. You are using “substitutionGroup” to use the abstract type (i.e. “elementType”) instead of enumerating every possible child element in a “xs:choice” block like I did. That has the advantage that you only need to inherit from the base type and don’t have to add the new sub type to the “xs:choice” block each time, which is quite elegant. The “disadvantage” is, that it is also possible to use the (probably abstract) base type (i.e. or ) to define an element, which is a bit unusual for users.



Anyway, I put your XSD into Visual Studio (which knows how to interpret “substitutionGroup”). Your XSD enables nested layers for example, which is not valid afaik.







Just a remark.



One more question. In your source package, there are files with the extension “.nxs”. Where does it come from? Some kind of XML database generator?