Multiple variations of a single entity
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 20
- Joined: Sat Nov 26, 2005 5:17 pm
- Location: Houston, Texas, USA
- Contact:
Multiple variations of a single entity
I'm running into trouble trying to figure out how to write a schema for validating an element that can have different appearances, depending on the value of an attribute. I'm not sure it can be done at all.
Here's an example of what we can do in our aircraft simulation model file:
<component name="Roll AP Wing Leveler" type="PURE_GAIN">
<input>fcs/attitude/sensor/phi-rad</input>
<gain>2.0</gain>
<clipto>
<min>-0.255</min>
<max>0.255</max>
</clipto>
</component>
<component name="Roll AP Error Integrator" type="INTEGRATOR">
<input> attitude/phi-rad </input>
<c1> 0.125 </c1>
</component>
<component name="Roll AP Error summer" type="SUMMER">
<input> velocities/p-rad_sec</input>
<input> fcs/roll-ap-wing-leveler</input>
<input> fcs/roll-ap-error-integrator</input>
<clipto>
<min>-1.0</min>
<max> 1.0</max>
</clipto>
</component>
<component name="Roll AP Autoswitch" type="SWITCH">
<default value="0.0"/>
<test logic="AND" value="fcs/roll-ap-error-summer">
ap/attitude_hold == 1
</test>
</component>
Each "component" element will have a name and a type attribute. Each component element can have one or more input elements. Each componentn may have zero or one output elements. THe specific content of the component will depend on which of several pre-defined types the component represents.
I tried using a choice and group structure, but that didn't quite work out. Am I out of luck?
Jon
Here's an example of what we can do in our aircraft simulation model file:
<component name="Roll AP Wing Leveler" type="PURE_GAIN">
<input>fcs/attitude/sensor/phi-rad</input>
<gain>2.0</gain>
<clipto>
<min>-0.255</min>
<max>0.255</max>
</clipto>
</component>
<component name="Roll AP Error Integrator" type="INTEGRATOR">
<input> attitude/phi-rad </input>
<c1> 0.125 </c1>
</component>
<component name="Roll AP Error summer" type="SUMMER">
<input> velocities/p-rad_sec</input>
<input> fcs/roll-ap-wing-leveler</input>
<input> fcs/roll-ap-error-integrator</input>
<clipto>
<min>-1.0</min>
<max> 1.0</max>
</clipto>
</component>
<component name="Roll AP Autoswitch" type="SWITCH">
<default value="0.0"/>
<test logic="AND" value="fcs/roll-ap-error-summer">
ap/attitude_hold == 1
</test>
</component>
Each "component" element will have a name and a type attribute. Each component element can have one or more input elements. Each componentn may have zero or one output elements. THe specific content of the component will depend on which of several pre-defined types the component represents.
I tried using a choice and group structure, but that didn't quite work out. Am I out of luck?
Jon
Jon Berndt
Development Coordinator
JSBSim Project
Open Source Flight Dynamics Model
http://www.jsbsim.org
Development Coordinator
JSBSim Project
Open Source Flight Dynamics Model
http://www.jsbsim.org
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Jon,
What you are trying to do is generally called co-occurrence constraint and it is not supported by the current XML Schema 1.0 language. It is on the todo list for the XML Schema 1.1 and 2.0.
Right now your alternatives are:
* Use Relax NG
* Relax the XML Schema constraint and use Schematron embedded rules to enforce the constraints
* Change the documents to use/define for instance a different element for each type value
* Use xsi:type in the instance document in the component element to specify the actual type for the content
Best Regards,
George
What you are trying to do is generally called co-occurrence constraint and it is not supported by the current XML Schema 1.0 language. It is on the todo list for the XML Schema 1.1 and 2.0.
Right now your alternatives are:
* Use Relax NG
* Relax the XML Schema constraint and use Schematron embedded rules to enforce the constraints
* Change the documents to use/define for instance a different element for each type value
* Use xsi:type in the instance document in the component element to specify the actual type for the content
Best Regards,
George
-
- Posts: 20
- Joined: Sat Nov 26, 2005 5:17 pm
- Location: Houston, Texas, USA
- Contact:
The first two alternatives sound ... "non-standard", to me. Is that true?george wrote:Hi Jon,
What you are trying to do is generally called co-occurrence constraint and it is not supported by the current XML Schema 1.0 language. It is on the todo list for the XML Schema 1.1 and 2.0.
Right now your alternatives are:
* Use Relax NG
* Relax the XML Schema constraint and use Schematron embedded rules to enforce the constraints
* Change the documents to use/define for instance a different element for each type value
* Use xsi:type in the instance document in the component element to specify the actual type for the content
Best Regards,
George
I may offer the third option as the preferred alternative definition, and make the current usage obsolete, eventually.
I am most intrigued by the fourth option you present above. What is that? I don't know what you are talking about (yet)!
Jon
Jon Berndt
Development Coordinator
JSBSim Project
Open Source Flight Dynamics Model
http://www.jsbsim.org
Development Coordinator
JSBSim Project
Open Source Flight Dynamics Model
http://www.jsbsim.org
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Jon,
Relax NG is a standard: ISO/IEC 19757-2 RELAX-NG
Schematron will also be an ISO standard soon.
Here it is an example of using xsi:type.
Schema file:
Instance document:
Best Regards,
George
Relax NG is a standard: ISO/IEC 19757-2 RELAX-NG
Schematron will also be an ISO standard soon.
Here it is an example of using xsi:type.
Schema file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="components">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="component"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="component" type="componentBase"/>
<!-- -->
<xs:complexType name="componentBase">
<xs:sequence/>
<xs:attribute name="name" use="required"/>
</xs:complexType>
<!-- -->
<xs:complexType name="PURE_GAIN">
<xs:complexContent>
<xs:extension base="componentBase">
<xs:sequence>
<xs:element ref="input"/>
<xs:element ref="gain"/>
<xs:element ref="clipto"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- -->
<xs:complexType name="INTEGRATOR">
<xs:complexContent>
<xs:extension base="componentBase">
<xs:sequence>
<xs:element ref="input"/>
<xs:element ref="c1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- -->
<xs:complexType name="SUMMER">
<xs:complexContent>
<xs:extension base="componentBase">
<xs:sequence>
<xs:element minOccurs="3" maxOccurs="3" ref="input"/>
<xs:element minOccurs="0" ref="clipto"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- -->
<xs:complexType name="SWITCH">
<xs:complexContent>
<xs:extension base="componentBase">
<xs:sequence>
<xs:sequence>
<xs:element ref="default"/>
<xs:element ref="test"/>
</xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- -->
<xs:element name="default">
<xs:complexType>
<xs:attribute name="value" use="required" type="xs:decimal"/>
</xs:complexType>
</xs:element>
<xs:element name="test">
<xs:complexType mixed="true">
<xs:attribute name="logic" use="required" type="xs:NCName"/>
<xs:attribute name="value" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="input" type="xs:string"/>
<xs:element name="c1" type="xs:decimal"/>
<xs:element name="gain" type="xs:decimal"/>
<xs:element name="clipto">
<xs:complexType>
<xs:sequence>
<xs:element ref="min"/>
<xs:element ref="max"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="min" type="xs:decimal"/>
<xs:element name="max" type="xs:decimal"/>
</xs:schema>
Code: Select all
<components xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<component name="Roll AP Wing Leveler" xsi:type="PURE_GAIN">
<input>fcs/attitude/sensor/phi-rad</input>
<gain>2.0</gain>
<clipto>
<min>-0.255</min>
<max>0.255</max>
</clipto>
</component>
<component name="Roll AP Error Integrator" xsi:type="INTEGRATOR">
<input> attitude/phi-rad </input>
<c1> 0.125 </c1>
</component>
<component name="Roll AP Error summer" xsi:type="SUMMER">
<input> velocities/p-rad_sec</input>
<input> fcs/roll-ap-wing-leveler</input>
<input> fcs/roll-ap-error-integrator</input>
<clipto>
<min>-1.0</min>
<max> 1.0</max>
</clipto>
</component>
<component name="Roll AP Autoswitch" xsi:type="SWITCH">
<default value="0.0"/>
<test logic="AND" value="fcs/roll-ap-error-summer"> ap/attitude_hold == 1</test>
</component>
</components>
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service