W3C home > Mailing lists > Public > xmlschema-dev@w3.org > October 2012

Re: Treatement of whitespace in enumerations

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Mon, 8 Oct 2012 17:11:03 +0530
Message-ID: <CABuuzNO4qw1Jw0A5uegewM071eaM1i_nuY0gEUWv_dsK6yvxCQ@mail.gmail.com>
To: ihe.onwuka@gmail.com
Cc: xmlschema-dev@w3.org
wrt this question, you recently wrote on xsl-list that you further had
a schema declaration as follows:

<xsd:element name="propertySubType" type="PropertySubTypeList"/>

<xsd:simpleType name="PropertySubTypeList">
   <xsd:list itemType="PropertySubType"/>
</xsd:simpleType>

and you validate an XML instance document like following,

<propertySubType>General Industrial</propertySubType>

with the above schema fragments.

The simple type definition "PropertySubType" that you've specified,
has spaces in the enumeration values. You then use, "PropertySubType"
as an itemType of the list. The problem with this approach is, that an
XML list instance by definition treats whitespace as a delimiter for
list items, which then cannot validate a value like "General
Industrial" correctly (because, this is broken down into two list
items "General" and "Industrial" and none of these are specified
within your enumerations in the schema). This explanation should
explain the problem you're facing in this case.

Now for the solutions. I feel, you should remodel the schema to fit
the facilities offered by the XSD language. Here's a modified approach
(one of the various, I believe) to solve this issue,

The schema (uses XSD 1.1 facilities):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

      <xs:element name="propertySubType" type="RestrictedList"/>
	
      <xs:simpleType name="RestrictedList">
	   <xs:restriction base="xs:string">
	         <xs:assertion test="every $val in tokenize($value,
'\r?\n')[not(normalize-space() = '')] satisfies
		                              ($val = ('Cold Store', 'Data Centre',
'Design and Build', 'Distribution Warehouse', 'General
Industrial'))"/>
	   </xs:restriction>
      </xs:simpleType>
	
</xs:schema>

A sample XML instance:

<?xml version="1.0" encoding="UTF-8"?>
<propertySubType>
General Industrial
Cold Store
General Industrial
Cold Store
Distribution Warehouse
</propertySubType>

With this solution,
a) the list instance is modeled as a xs:string type. The list items
are delimited by CR?LF pairs.
b) the list items are constrained to belong to a specific value space,
by using an xs:assertion facet. this is similar to, what you're trying
to do with xs:enumeration facets. this approach doesn't suffer from,
issue of whitespaces within list items.

Some other points to note,
a) the delimiter within the list can be set to other characters also
(for e.g ',' or whatever suits you. make sure, that the delimiter
doesn't exists in data values). then you don't need to establish list
items by indentation semantics (it doesn't look artful!).
b) if the list instance is within attribute values, then you can't
rely on indentation to establish list items. in this case, you can use
a delimiter like ',' etc.

On Sat, Oct 6, 2012 at 7:01 PM, Ihe Onwuka <ihe.onwuka@gmail.com> wrote:
> I have an restriction by enumeration as follows
>
> <xsd:simpleType name="PropertySubType">
>         <xsd:restriction base="xsd:string">
>             <xsd:enumeration value="Cold Store"/>
>             <xsd:enumeration value="Data Centre"/>
>             <xsd:enumeration value="Design and Build"/>
>             etc.....
>
> If in my instance I have an element that uses the above data type and
> say has value Data Centre I get an error
>
> cvc-enumeration-valid: Value 'General' is not facet-valid with respect
> to enumeration '[Cold Store, Data Centre, Design and Build,
> Distribution Warehouse, etc.......]'. It must be a value from the
> enumeration.
>
> So it is not recongnising space seperated enumerations..
>
> Schema is validated with Xerces 1.1
>
> Thanks
>




-- 
Regards,
Mukul Gandhi
Received on Monday, 8 October 2012 11:41:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:16:02 UTC