[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
XSD 1.1 assertions are a great mistery for me
- From: cmarchand@oxiane.com
- To: xml-dev@lists.xml.org
- Date: Wed, 29 Mar 2017 15:20:45 +0200
Hello !
I want to define a complex type that represents a parameter.
A parameter MUST have a @name
A parameter MAY have a @as
A parameter has either a @value, or a @abstract
A parameter that has a @abstract MUST have @as
I've defined this :
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
vc:minVersion="1.1">
<xs:element name="data">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="param" type="TParam"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="TParam">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="as" type="xs:string" use="optional"/>
<xs:attribute name="value" type="xs:string" use="optional"/>
<xs:attribute name="abstract" fixed="true" use="optional" />
<xs:assert test="count(@value | @abstract) eq 1" id="assert1"/>
<xs:assert test="if(exists(@abstract)) then exists(@as) else true()"
id="assert2"/>
</xs:complexType>
</xs:schema>
And this file :
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="param.xsd">
<param name="p1" /> <!-- should fail
assert1 -->
<param name="p2" value="v2"/> <!-- should be valid
-->
<param name="p3" value="v3" as="xs:string"/> <!-- should be valid
-->
<param name="p4" as="xs:string" abstract="true"/> <!-- should be valid
-->
<param name="p5" abstract="true"/> <!-- should fail
assert2 -->
<param name="p6" abstract="true" value="v6"/> <!-- should fail
assert2 -->
</data>
All param except p4 are invalid.
p1 fails assert2
p2 fails assert1 & assert2
p3 fails assert2
p4 is valid
p5 fails assert2
p6 fails assert1 & assert2
I do not know what I miss... Any help will be much appreciated !
Best,
Christophe
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]