- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: 15 Jan 2002 09:34:22 +0000
- To: xiaofeng.wang@ps.ge.com
- Cc: xmlschema-dev@w3.org
xiaofeng.wang@ps.ge.com writes: > Hello everybody: > > I found a hard time to map inheritance defined in UML to XML Schema. > Usually, the complex type extension is used for inheritance. Then, two > issues raised: > > (1) Use <sequence> or <all> ? > <sequence> specify the order of elements defined in it. But in UML, there is > no such specification for order. Attributes and associations defined in a > class may appear in any order. It seems <all> is good choice (??) If order doesn't signify, then pick an order and enforce it -- use <sequence>. > (2) How to use <all> > <all> does provide the flexibility for order. But it has other restrictions. > It seems hard for me to handle multi-level inheritance defined in UML. > Reference [1] shows an example for mapping Inheritance defined in UML to XML > Schema. It looks like: > > <xsd:element name = "Address" type = "Address" abstract = "true"/> > <xsd:complexType name = "Address" abstract = "true"> > <xsd:all> > <xsd:element name = "name" type = "xsd:string"/> > <xsd:element name = "street" type = "xsd:string"/> > <xsd:element name = "city" type = "xsd:string"/> > </xsd:all> > </xsd:complexType> > <xsd:element name = "USAddress" type = "USAddress" substitutionGroup > = "Address"/> > <xsd:complexType name = "USAddress"> > <xsd:complexContent> > <xsd:extension base = "Address"> > <xsd:all> > <xsd:element name = "state" type = > "xsd:string"/> > <xsd:element name = "zip" type = > "xsd:positiveInteger"/> > </xsd:all> > </xsd:extension> > </xsd:complexContent> > </xsd:complexType> > > This schema can't pass the validation check, and the error is "groups are > not allowed in ALL element". > But if I change the <all> defined in the base complex type to <sequence>, it > passed the validation check without any error. Could anybody please explain > this? See previous threads. Extension _always_ results in a top-level <sequence>, but <all> may not be nested. So use <sequence>, as I said above. > If I define "MyAddress" as a sub-class of "USAddress", can I write the > schema like the following? I changed <all> of base class to <sequence> and > defined "MyAddress" as a child of "USAddress". > > <xsd:element name = "Address" type = "Address" abstract = "true"/> > <xsd:complexType name = "Address" abstract = "true"> > <xsd:sequence> > <xsd:element name = "name" type = "xsd:string"/> > <xsd:element name = "street" type = "xsd:string"/> > <xsd:element name = "city" type = "xsd:string"/> > </xsd:sequence> > </xsd:complexType> > <xsd:element name = "USAddress" type = "USAddress" substitutionGroup > = "Address"/> > <xsd:complexType name = "USAddress"> > <xsd:complexContent> > <xsd:extension base = "Address"> > <xsd:all> > <xsd:element name = "state" type = > "xsd:string"/> > <xsd:element name = "zip" type = > "xsd:positiveInteger"/> > </xsd:all> > </xsd:extension> > </xsd:complexContent> > </xsd:complexType> > <xsd:element name = "MyAddress" type = "MyAddress"/> > <xsd:complexType name = "MyAddress"> > <xsd:complexContent> > <xsd:extension base = "USAddress"> > <xsd:all> > <xsd:element name = "Mystate" type = > "xsd:string"/> > <xsd:element name = "Myzip" type = > "xsd:positiveInteger"/> > </xsd:all> > </xsd:extension> > </xsd:complexContent> > </xsd:complexType> No -- still you end up with a nested <all>, not allowed -- use <sequence>. ht -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh W3C Fellow 1999--2001, part-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/
Received on Tuesday, 15 January 2002 04:34:29 UTC