Jump to content
ninja.1200

Inheritance/Interfaces .. a difficult example

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!!!!!

Edited by ninja.1200
  • Like 1

Share this post


Link to post
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).

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...