← Prev in month
← Prev in thread
Type inheritance in XML Schema
Hi all, I want to use the concept of type inheritance in W3C XML Schema. I am trying to write a small Schema for the same. Below is my attempt. <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <xs:complexType name="shape"> <xs:all> <xs:element name="id" type="xs:string" /> <xs:element name="attr2" type="xs:string" /> </xs:all> </xs:complexType> <xs:complexType name="circle"> <xs:complexContent> <xs:extension base="shape"> <xs:all> <xs:element name="radius" type="xs:float" /> </xs:all> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="rectangle"> <xs:complexContent> <xs:extension base="shape"> <xs:all> <xs:element name="side1" type="xs:float" /> <xs:element name="side2" type="xs:float" /> <xs:element name="side3" type="xs:float" /> <xs:element name="side4" type="xs:float" /> </xs:all> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="OBJECTS"> <xs:complexType> <xs:all> <xs:element name="A" type="circle"/> <xs:element name="B" type="rectangle"/> </xs:all> </xs:complexType> </xs:element> </xs:schema> I am creating a base type called "shape". The subtypes "circle" and "rectangle" derive from this base type. I want to use something like xs:all, because I want to keep the elements unordered. But the above XML Schema is wrong, and the validator complains about xs:all. My questions are.. 1) What will be the right syntax for type inheritance for the requirement above? 2) Will trying to map the OO inheritance concepts to XML Schema be the right design approach? -- Regards, Mukul Gandhi
← Prev in month
← Prev in thread