Restricting a type by using an attribute on the element using the type?

Discussion in 'XML' started by Arndt Jonasson, Feb 9, 2007.

  1. This is a modelling style question, I think.

    I am working with a somewhat XML Schema-like formalism which defines
    the structure of an instance document, supplying a number of built-in
    types (a very light-weight Schema).

    One of the built-in types is called "ref", and its defined values are
    location paths to other elements in the instance document.

    An example:

    <spec xmlns:types="urn:example:mytypes.1">
    <e name="top">
    <e name="a" type="types:int" minOccurs="0"/>
    <e name="elts">
    <e name="e1" type="types:int"/>
    <e name="e2" type="types:string"/>
    <e name="e3" type="types:ref"/>
    </e>
    </e>
    </spec>

    This is a valid instance of the above:

    <top>
    <a>3</a>
    <elts>
    <e1>1</e1>
    <e2>earth</e2>
    <e3>/top/a</e3>
    </elts>
    </top>

    My question deals with how best to specify additional parameters of
    the
    "ref" type. One thing I'd like to be able to say is "the element
    pointed
    to by the location path must actually exist", respectively "does not
    have to exist" (elements can be created and destroyed in runtime).

    This can be expressed with an attribute to the <e/> element:

    <e name="e3" type="types:ref" must_exist="true"/>

    My question is: is this a proper way of doing it? It seems slightly
    peculiar to supply the general </e> element with an attribute which
    will only be valid for one particular value of another attribute.

    (Of course I can make a "types:ref_must_exists" type, but there will
    be more complicated ways to restrict the type.)
    Arndt Jonasson, Feb 9, 2007
    #1
    1. Advertising

  2. Hi Arndt,

    "Arndt Jonasson" <> writes:

    > My question deals with how best to specify additional parameters of
    > the
    > "ref" type. One thing I'd like to be able to say is "the element
    > pointed
    > to by the location path must actually exist", respectively "does not
    > have to exist" (elements can be created and destroyed in runtime).
    >
    > This can be expressed with an attribute to the <e/> element:
    >
    > <e name="e3" type="types:ref" must_exist="true"/>
    >
    > My question is: is this a proper way of doing it? It seems slightly
    > peculiar to supply the general </e> element with an attribute which
    > will only be valid for one particular value of another attribute.
    >
    > (Of course I can make a "types:ref_must_exists" type, but there will
    > be more complicated ways to restrict the type.)


    Your must_exist attribute is changing the ref type, not the element
    so it naturally belongs to the type definition. XML Schema does this
    by allowing you to create a new type that restrict the original. In
    your case it could look like so:


    <t name="my_t">
    <r base="types:ref" must_exist="true"/>
    </t>

    <e name="e3" type="my_t"/>

    You could have several attributes/elements like must_exist that
    change different aspects of different types.


    hth,
    -boris

    --
    Boris Kolpackov
    Code Synthesis Tools CC
    http://www.codesynthesis.com
    Open-Source, Cross-Platform C++ XML Data Binding
    Boris Kolpackov, Feb 9, 2007
    #2
    1. Advertising

  3. On Feb 9, 6:04 pm, Boris Kolpackov <> wrote:
    > Hi Arndt,
    >
    >
    >
    > "Arndt Jonasson" <> writes:
    > > My question deals with how best to specify additional parameters of
    > > the
    > > "ref" type. One thing I'd like to be able to say is "the element
    > > pointed
    > > to by the location path must actually exist", respectively "does not
    > > have to exist" (elements can be created and destroyed in runtime).

    >
    > > This can be expressed with an attribute to the <e/> element:

    >
    > > <e name="e3" type="types:ref" must_exist="true"/>

    >
    > > My question is: is this a proper way of doing it? It seems slightly
    > > peculiar to supply the general </e> element with an attribute which
    > > will only be valid for one particular value of another attribute.

    >
    > > (Of course I can make a "types:ref_must_exists" type, but there will
    > > be more complicated ways to restrict the type.)

    >
    > Your must_exist attribute is changing the ref type, not the element
    > so it naturally belongs to the type definition. XML Schema does this
    > by allowing you to create a new type that restrict the original. In
    > your case it could look like so:
    >
    > <t name="my_t">
    > <r base="types:ref" must_exist="true"/>
    > </t>
    >
    > <e name="e3" type="my_t"/>
    >
    > You could have several attributes/elements like must_exist that
    > change different aspects of different types.


    Creating a subtype feels conceptually cleaner, but since this is text
    that humans are supposed to write, I think the users may feel that it
    gets unnecessarily cluttered with having to create subtypes which
    are only used once.

    Thank you for your answer.
    Arndt Jonasson, Feb 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andy2o
    Replies:
    4
    Views:
    276
  2. anonymous
    Replies:
    1
    Views:
    5,952
  3. =?Utf-8?B?TWFyaw==?=
    Replies:
    4
    Views:
    632
    =?Utf-8?B?TWFyaw==?=
    Dec 14, 2006
  4. perspolis
    Replies:
    1
    Views:
    2,564
    Mark Rae
    Jan 23, 2007
  5. Joe Kovac
    Replies:
    2
    Views:
    952
    Joe Kovac
    May 2, 2007
Loading...

Share This Page