xsd:all too restrictive, what do I use?
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 3
- Joined: Thu Aug 26, 2010 1:00 am
xsd:all too restrictive, what do I use?
Hi all, and thanks in advance for any advice;
I am trying to represent some XML in an XSD schema, but having troubles.
I need to make a schema that allows for, something which was inspired from ANT, and looks like this;
where the 'and', 'or', and 'not' elements must be able to accept any number of child 'and', 'or', 'not', and 'equals' elements.
There must not be any order restrictions.
That is, I think the xsd:all element almost suits the occasion, but not the cardinality requirements.
The 'when' tag is easier. It can take either 'and, equals, or, not' elements (that is the easy part, simply use an xsd:choice element.
Can anyone show me how I would define a schema which allows for the above XML?
I am trying to represent some XML in an XSD schema, but having troubles.
I need to make a schema that allows for, something which was inspired from ANT, and looks like this;
Code: Select all
<when result="template.txt">
<and>
<equals property="Department" value="Finance"/>
<equals property="Size" value="1"/>
<or>
<equals property="User" value="John"/>
<equals property="User" value="Admin"/>
</or>
</and>
</when>
There must not be any order restrictions.
That is, I think the xsd:all element almost suits the occasion, but not the cardinality requirements.
The 'when' tag is easier. It can take either 'and, equals, or, not' elements (that is the easy part, simply use an xsd:choice element.
Can anyone show me how I would define a schema which allows for the above XML?
-
- Posts: 3
- Joined: Thu Aug 26, 2010 1:00 am
Re: xsd:all too restrictive, what do I use?
Actually, having posted the question, and continued to research, I came up with what i think is the answer.
I can use a <xs:choice> element with an unbounded cardinality.
i.e., here I defined my types separately:
And it seems to be correct.
Though, feel free to correct me if I have come to the wrong understanding!
I can use a <xs:choice> element with an unbounded cardinality.
i.e., here I defined my types separately:
Code: Select all
<xs:complexType name="SequentialLogicType">
<xs:choice maxOccurs="unbounded">
<xs:element name="equals" type="EqualsType" />
<xs:element name="and" type="SequentialLogicType" />
<xs:element name="or" type="SequentialLogicType" />
<xs:element name="not" type="SimpleLogicType" />
</xs:choice>
</xs:complexType>
<xs:complexType name="EqualsType">
<xs:attribute name="property" type="xs:string" />
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
<xs:complexType name="SimpleLogicType">
<xs:choice>
<xs:element name="equals" type="EqualsType" />
<xs:element name="and" type="SequentialLogicType" />
<xs:element name="or" type="SequentialLogicType" />
<xs:element name="not" type="SimpleLogicType" />
</xs:choice>
</xs:complexType>
Though, feel free to correct me if I have come to the wrong understanding!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: xsd:all too restrictive, what do I use?
Hello,
It seems to be correct. The only thing I would add is a minOccurs="2" for the xs:choice of SequentialLogicType:
since the logical operations "and" and "or" need at least two operands to have a purpose.
Regards,
Adrian
It seems to be correct. The only thing I would add is a minOccurs="2" for the xs:choice of SequentialLogicType:
Code: Select all
<xs:complexType name="SequentialLogicType">
<xs:choice minOccurs="2" maxOccurs="unbounded">
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
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