enumeration-facet of union types [message #54988] |
Tue, 23 November 2004 07:29  |
Eclipse User |
|
|
|
Hi,
I have a question about enumeration facets of union types. I have the
following schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="test" type="st.unionType"/>
<xs:simpleType name="st.unionType">
<xs:restriction>
<xs:simpleType>
<xs:union memberTypes="xs:string xs:integer"/>
</xs:simpleType>
<xs:enumeration value="11"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
I had a look into the implementation of the type system in XSD. I've seen
that xs:string is represented by the Java String-type and xs:integer is
represented by BigDecimal.
So the value space of the anonymous sub union-type would contain String and
BigDecimal values. If I restrict this type with the enumeration facet I'm
not sure whether the value space of "st.unionType" would contain
String("11") and BigDecimal("11") or only String("11").
In the datatypes part of the W3C it is said that a lexical value is
validated against the memberTypes until a match is found but the evaluation
order can be overridden with the use of xsi:type.
So from my point of view it should be possible to validate the following
file against the schema from above:
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation="test.xsd" xsi:type="xs:integer">
11
</test>
And Xerces-C also successfully validates this file. So I think the value
space of "st.unionType" should contain BigDecimal("11") and String("11).
But at the moment if I call the function XSDEnumerationFacet.getValue() on
the enumeration facet of "st.unionType" I only get one Object, the
String("11") and not also BigDecimal("11"). I would interpret this result
that XSD only puts String("11") into the value space of "st.unionType" and
not also BigDecimal("11"). Is this correct (my interpretation and/or the
behaviour of XSD)?
Regards
Klaas Dellschaft
|
|
|
Re: enumeration-facet of union types [message #55015 is a reply to message #54988] |
Tue, 23 November 2004 08:15   |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Klass,
When the model sees value="11" it must determine the "actual value" of
the literal using the base type of the restriction, and that union will
accept 11 as a value of type string, so that's the one and only value in
the enumeration. There isn't even the slightest hint in the enumeration
description in the spec to indicate that the single literal value must
be converted to more than one valid value if the base type is a union.
And even the comment about the use of xsi:type does not have any direct
bearing on how enumeration is interpreted, because it talks only about a
union. In fact, it seems very reasonable to argue that only the String
11 should be in the enumeration and that BigDecimal 11 should not, and
hence that the instance should not validate. I can see how other
interpretations would be reasonable, but there really needs to be some
explicit wording in the spec to support such alternative interpretations...
(I'm curious if the instance would validate if the xsi:type were int.)
Klaas Dellschaft wrote:
>Hi,
>
>I have a question about enumeration facets of union types. I have the
>following schema:
>
><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
> <xs:element name="test" type="st.unionType"/>
>
>
> <xs:simpleType name="st.unionType">
> <xs:restriction>
> <xs:simpleType>
> <xs:union memberTypes="xs:string xs:integer"/>
> </xs:simpleType>
> <xs:enumeration value="11"/>
> </xs:restriction>
> </xs:simpleType>
>
></xs:schema>
>
>
>I had a look into the implementation of the type system in XSD. I've seen
>that xs:string is represented by the Java String-type and xs:integer is
>represented by BigDecimal.
>
>So the value space of the anonymous sub union-type would contain String and
>BigDecimal values. If I restrict this type with the enumeration facet I'm
>not sure whether the value space of "st.unionType" would contain
>String("11") and BigDecimal("11") or only String("11").
>
>In the datatypes part of the W3C it is said that a lexical value is
>validated against the memberTypes until a match is found but the evaluation
>order can be overridden with the use of xsi:type.
>
>So from my point of view it should be possible to validate the following
>file against the schema from above:
>
><test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xsi:noNamespaceSchemaLocation="test.xsd" xsi:type="xs:integer">
> 11
></test>
>
>And Xerces-C also successfully validates this file. So I think the value
>space of "st.unionType" should contain BigDecimal("11") and String("11).
>
>But at the moment if I call the function XSDEnumerationFacet.getValue() on
>the enumeration facet of "st.unionType" I only get one Object, the
>String("11") and not also BigDecimal("11"). I would interpret this result
>that XSD only puts String("11") into the value space of "st.unionType" and
>not also BigDecimal("11"). Is this correct (my interpretation and/or the
>behaviour of XSD)?
>
>Regards
>Klaas Dellschaft
>
>
>
>
>
|
|
|
|
Re: enumeration-facet of union types [message #57797 is a reply to message #55141] |
Wed, 16 February 2005 07:13  |
Eclipse User |
|
|
|
Hi,
as I said I've put this question on the W3C mailing list. It seems that XSD
as well as Xerces shows the correct behaviour. This is caused by a bug in
the XML Schema definition:
It is a bit confusing that xsi:type should change the evaluation order of
the types participating in a union. Instead xsi:type has the effect that a
value isn't evaluated against the union type but against the type given in
xsi:type. So xsi:type circumvents the facets attached to the union type.
So you are correct if you only put the string "11" into the list of allowed
enumeration values. But also Xerces is right if it successfuly validates
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation="test.xsd" xsi:type="xs:integer">
11
</test>
because xs:integer is validly derived from one of the unions member types
(Condition 2.2.4 in [2]). Also if you use xs:int or xs:unsignedByte as the
value of xsi:type Xerces should validate the document above.
Cheers
Klaas
[1] http://lists.w3.org/Archives/Public/xmlschema-dev/2005Jan/00 06.html
[2] http://www.w3.org/TR/xmlschema-1/#cos-st-derived-ok
|
|
|
Re: enumeration-facet of union types [message #592591 is a reply to message #54988] |
Tue, 23 November 2004 08:15  |
Eclipse User |
|
|
|
Klass,
When the model sees value="11" it must determine the "actual value" of
the literal using the base type of the restriction, and that union will
accept 11 as a value of type string, so that's the one and only value in
the enumeration. There isn't even the slightest hint in the enumeration
description in the spec to indicate that the single literal value must
be converted to more than one valid value if the base type is a union.
And even the comment about the use of xsi:type does not have any direct
bearing on how enumeration is interpreted, because it talks only about a
union. In fact, it seems very reasonable to argue that only the String
11 should be in the enumeration and that BigDecimal 11 should not, and
hence that the instance should not validate. I can see how other
interpretations would be reasonable, but there really needs to be some
explicit wording in the spec to support such alternative interpretations...
(I'm curious if the instance would validate if the xsi:type were int.)
Klaas Dellschaft wrote:
>Hi,
>
>I have a question about enumeration facets of union types. I have the
>following schema:
>
><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
> <xs:element name="test" type="st.unionType"/>
>
>
> <xs:simpleType name="st.unionType">
> <xs:restriction>
> <xs:simpleType>
> <xs:union memberTypes="xs:string xs:integer"/>
> </xs:simpleType>
> <xs:enumeration value="11"/>
> </xs:restriction>
> </xs:simpleType>
>
></xs:schema>
>
>
>I had a look into the implementation of the type system in XSD. I've seen
>that xs:string is represented by the Java String-type and xs:integer is
>represented by BigDecimal.
>
>So the value space of the anonymous sub union-type would contain String and
>BigDecimal values. If I restrict this type with the enumeration facet I'm
>not sure whether the value space of "st.unionType" would contain
>String("11") and BigDecimal("11") or only String("11").
>
>In the datatypes part of the W3C it is said that a lexical value is
>validated against the memberTypes until a match is found but the evaluation
>order can be overridden with the use of xsi:type.
>
>So from my point of view it should be possible to validate the following
>file against the schema from above:
>
><test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xsi:noNamespaceSchemaLocation="test.xsd" xsi:type="xs:integer">
> 11
></test>
>
>And Xerces-C also successfully validates this file. So I think the value
>space of "st.unionType" should contain BigDecimal("11") and String("11).
>
>But at the moment if I call the function XSDEnumerationFacet.getValue() on
>the enumeration facet of "st.unionType" I only get one Object, the
>String("11") and not also BigDecimal("11"). I would interpret this result
>that XSD only puts String("11") into the value space of "st.unionType" and
>not also BigDecimal("11"). Is this correct (my interpretation and/or the
>behaviour of XSD)?
>
>Regards
>Klaas Dellschaft
>
>
>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03763 seconds