- From: Costello, Roger L. <costello@mitre.org>
- Date: Wed, 29 Aug 2012 15:09:28 +0000
- To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Folks, Hello, In XML Schema 1.1 you can declare an element to be substitutable for multiple elements, e.g., <element name="Example" substitutionGroup="A B C" ...> Recall that in XML Schema 1.0 if you declared an element and didn't provide a type, then it inherits the type of its head element, e.g., <xs:element name="Subway" type="xs:string" /> <xs:element name="Metro" substitutionGroup="Subway" /> Note that Metro does not specify a type so it inherits Subway's type. Thus the type of Metro is xs:string. But in XML Schema 1.1 there can be multiple head elements, so what type would the element inherit? Example: The Comment element is substitutable for Subway (xs:string), isHardcover (xs:boolean), and TodaysDate (xs:date): <xs:element name="Subway" type="xs:string" /> <xs:element name="Metro" substitutionGroup="Subway" /> <xs:element name="isHardcover" type="xs:boolean" /> <xs:element name="TodaysDate" type="xs:date" /> <xs:element name="Comment" substitutionGroup="Subway isHardcover TodaysDate" /> Also notice that Comment does not specify a type. So what is Comment's data type? Scroll down to see the answer .... Answer: Comment inherits the data type of the first head element listed. In this case Subway is listed first, so Comment has the xs:string data type. Suppose that Comment was declared like this: <xs:element name="Comment" substitutionGroup=" isHardcover Subway TodaysDate" /> Now isHardcover is listed first, so Comment has the xs:boolean data type. Here is the relevant section from the XML Schema 1.1 specification: An <element> with no referenced or included type definition will correspond to an element declaration which has the same type definition as the *first* substitution-group head named in the substitutionGroup LESSON LEARNED: THE ORDER OF ELEMENTS LISTED IN A SUBSTITUTIONGROUP IS EXTREMELY IMPORTANT.
Received on Wednesday, 29 August 2012 15:10:04 UTC