- From: C. M. Sperberg-McQueen <cmsmcq@acm.org>
- Date: Wed, 17 May 2000 15:22:26 -0600
- To: "Dr. Ardeshir Bahreininejad" <bahreininejad@yahoo.com>, www-xml-schema-comments@w3.org
At 07:57 00/05/03 -0700, Dr. Ardeshir Bahreininejad wrote: >Hi, > >I wish to define an element in a schema document where >the "name" of the element is not known. Let's say, the >name of the element may be decided by other parties >using the schema for example: ><element name="Cat"/> ><element name="Dog"/> ><element name="????"/> where a different user may >decide on the ????. How do we define such dynamic name >allocation? I can think of two methods of achieving this effect. 1 Entity hack. Place the generic identifier (the name of the element type) into a general entity. The schema user specifies a name by defining the appropriate general entity, in the internal DTD-subset of the schema document. A schema which declares three element types named 'Cat', 'Dog', and something-to-be-determined-later might look like this. In the body of the schema, we use an entity reference where the user-specified name is to go: <xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <xsd:element name="Cat"/> <xsd:element name="Dog"/> <xsd:element name="&animal;"/> </xsd:schema> (All examples coded by hand, not validated. Check for typos before copying into production schemas ...) This part of the schema can remain the same for all users. At the top of the file, we have the XML declaration as usual, and in the internal subset of the document type declaration, we define the entity 'animal' as having the value parakeet. <?xml version="1.0"?> <!DOCTYPE xsd:schema PUBLIC "-//W3C//DTD XML Schema 20000406//EN" "XMLSchema.dtd" [ <!ENTITY % p 'xsd:'> <!ENTITY % s ':xsd'> <!ENTITY animal 'parakeet'> ]> When used with this prolog, the schema above declares element types named 'Cat', 'Dog', and 'parakeet'. To change the name of the third type, a user of the schema can simply substitute a different declaration for 'animal'. 2 Equivalence class hack. Declare an abstract element: we'll call it 'animal': <xsd:element name='animal' abstract='true' /> The user of the schema can declare an element type with any name they like, and specify that it is equivalent to your 'animal' element. <xsd:element name='parakeet' equivClass="Bahreininejad:animal" .../> There are two salient restrictions: First, the type of 'parakeet' must be derived from the type of 'animal' (this allows the creator of a module to enforce certain expectations about what can occur where an animal is expected). And second, 'parakeet' is allowed to be a member only of one equivalence class. In complex cases this may become burdensome, but this restriction is a fairly simple way to help avoid or at least control ambiguity. I hope this helps. -C. M. Sperberg-McQueen
Received on Wednesday, 17 May 2000 18:44:21 UTC