Jump to content

Inheritance/Interfaces .. a difficult example


ninja.1200

Recommended Posts

Hi all!I am working on a schema file where I want to use something like inheritance or interfaces (cf. Java), but I don't have any idea how to start. In particular, I would like to realize the following example. In schema A I define the general structure of an entity:

<xs:element name="elem" type="xs:string">  <xs:attribute name="attr" type="xs:string" /></xs:element>

An instance would look like this:

<elem attr="anything" />

In schema B I would like to refine the attribute type mentioned in schema A:

???<xs:attribute name="attr">  <xs:simpleType>	<xs:restriction base="xs:string">	  <xs:enumeration value="value1" />	  <xs:enumeration value="value2" />	</xs:restriction>  </xs:simpleType></xs:attribute>???

So that I can decide in an instance if I want to use the general definition or the refined one, e.g. by using a prefix:

<elem attr="anything" />or<elem attr="B:value1" /><elem attr="B:value2" />

Basically, I want to put special values for attributes in an external schema file (as kind of a taxonomy) and decide in an instance if I want to use the general definition or the specialzed one. In the general schema I don't want to place anything that is related to the specialized values so that I could define lots of specialized schemas (other taxonomies) without the need to change the general schema. Hope you got my idea.. Does anyone have an idea whether this is possible an how I have to build my schemas and instances to achieve this?Thanks in advance!!!!!

Link to comment
Share on other sites

There are the so called "abstract types" which are basically that.You define the common parts as an abstract type, and the details in non-abstract types. In the instance document, you add xsi:type attribute specifying the actual type you want. Here's one example, and here's another that follows a similar idea, though limited (I'm guessing for the sake of showing the RelaxNG equivalent).

Link to comment
Share on other sites

Thank you very much! I went through the tutorials you mentioned and finally I decided to use substitutionGroups in order to solve my problem. With these groups I can do something like this:

<elem attr="anything" /><B:elem attr="value1" />

I can use the element prefix to recognize whether a special attribute value is used or not, even in nested structures.

<elem attr="anything">  <child attr="anything" />  <B:child attr="value1" /></elem>

The only thing that does not work as intended: for the substituted elements I always have to specify a prefix even if I refer to the general definition in schema A. Actually, the example above only works in this way:

<elem attr="anything">  <A:child attr="anything" />  <B:child attr="value1" /></elem>

Definition of a default namespace does not help. Any suggestions?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...