- From: Krzysztof FF <Krzysztof.Finowicki@tessel.pl>
- Date: Thu, 3 Dec 2009 08:13:30 -0800 (PST)
- To: xmlschema-dev@w3.org
Hi all, I'm trying to define two-level layered schema - one with generic "system" model, second with specific "application" model. When trying to expose application data using generic system model elements specified by using xsi:type attribute referring to application model types, I've encountered some asymetry in treating it while validating data. My example is somehow simplified so as to reflect the issue from topic. Let's start with system schema, sys.xsd: <schema targetNamespace="http://www.org.com/SYS" xmlns:sys="http://www.org.com/SYS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <element name="Entity" type="sys:EntityType"/> <complexType name="EntityType"> <sequence minOccurs="0" maxOccurs="unbounded"> <element ref="sys:category"/> </sequence> </complexType> <element name="category" type="sys:CategoryType"/> <simpleType name="CategoryType"> <restriction base="string"/> </simpleType> </schema> Now I want to define specific rules for Room derived from Entity by restriction in app.xsd: <schema targetNamespace="http://www.org.com/APP" xmlns:app="http://www.org.com/APP" xmlns:sys="http://www.org.com/SYS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <import namespace="http://www.org.com/SYS" schemaLocation="sys.xsd"/> <element name="Room" type="app:RoomType" substitutionGroup="sys:Entity" /> <complexType name="RoomType"> <complexContent> <restriction base="sys:EntityType"> <sequence> <element ref="app:roomCategory"></element> </sequence> </restriction> </complexContent> </complexType> <element name="roomCategory" type="app:RoomCategoryType" substitutionGroup="sys:category"/> <simpleType name="RoomCategoryType"> <restriction base="sys:CategoryType"> <enumeration value="living"></enumeration> <enumeration value="bedroom"></enumeration> <enumeration value="kitchen"></enumeration> </restriction> </simpleType> </schema> Now I can write data using application model: <Room> <!-- namespaces omitted for brevity --> <roomCategory>living</roomCategory> </Room> I could write the same data using plain system model, because Room is derived from Entity by restriction: <sys:Entity> <!-- namespaces omitted for brevity --> <sys:category>living</sys:category> </sys:Entity1> The reason for flattening data to system model is to make it understandable for some low-level processing, whatever it is (i.e. without exact knowledge on application specifics). But there are some drawbacks: - validation can be made only against system schema, not application schema; - information about actual application types has been stripped out, although it could be of later use for some high-level processing, whatever it is (i.e. using knowledge of aplication specifics). My natural attempt was to use xsi:type attribute. But it occured that I can write <sys:Entity xsi:type="RoomType"> <!-- namespaces omitted for brevity --> <roomCategory>living</roomCategory> </sys:Entity1> OR <sys:Entity> <!-- namespaces omitted for brevity --> <sys:category xsi:type=RoomCategoryType">living</sys:category> </sys:Entity> BUT USING xsi:type on both levels is illegal: <sys:Entity xsi:type="RoomType"> <!-- namespaces omitted for brevity --> <sys:category xsi:type=RoomCategoryType">living</sys:category> </sys:Entity1> It seems that xsi:type "works" inwards, forcing inner content of element to be validated along referred type. But in the same time, it does not work outwards, i.e. inner element is not exposed as referred type - element name is interpreted explicitly instead. This is what I assume some drawback in how XML schema works, and causes my concept for exposing data using layered schemas to be illegal. I wonder if somebody could explain if there are some valid reasons for hiding xsi:type attribute referred from inner elements to their parent elements. -- View this message in context: http://old.nabble.com/Why-xsi%3Atype-works-only-inwards%2C-not-outwards--tp26628621p26628621.html Sent from the w3.org - xmlschema-dev mailing list archive at Nabble.com.
Received on Thursday, 3 December 2009 18:30:11 UTC