restrict IDREF to special elements

Discussion in 'XML' started by Hauke Fuhrmann, Oct 26, 2003.

  1. Hello,

    You can use the attribute type IDREF, if you want to make a reference to
    the ID of other elements like so:
    Also z.B.:

    <entry id="e1" name="n1" phonenumber="p1"/>

    <name id="n1" firstname="Robert" surname="Mustermann"/>
    <phone id="p1" number="1234567"/>

    In the schema definition the attributes "name" and "phonenumber" will be
    typed as xs:IDREF.
    The validator will check, if the IDs of all elements are unique and if
    the Values of those Attributes are from within these IDs.

    This is my question: How can I restrict the set of valid IDs for a
    special attribute to a smaller subset of IDs?
    For example I want to force the attribute "name" to only use references
    to name-elements and "phonenumber" to only use references to
    phone-elements, in order to not allow such thing:
    <entry id="e1" name="p1" phonenumber="n1"/>

    how do I do that?

    greetings,
    Hauke
    Hauke Fuhrmann, Oct 26, 2003
    #1
    1. Advertising

  2. Hauke Fuhrmann

    Mark Preston Guest

    On Sun, 26 Oct 2003 12:08:41 +0100, Hauke Fuhrmann
    <> wrote:

    >You can use the attribute type IDREF, if you want to make a reference to
    >the ID of other elements like so:
    >
    ><entry id="e1" name="n1" phonenumber="p1"/>
    >
    ><name id="n1" firstname="Robert" surname="Mustermann"/>
    ><phone id="p1" number="1234567"/>
    >
    >In the schema definition the attributes "name" and "phonenumber" will be
    > typed as xs:IDREF.
    >The validator will check, if the IDs of all elements are unique and if
    >the Values of those Attributes are from within these IDs.
    >
    >This is my question: How can I restrict the set of valid IDs for a
    >special attribute to a smaller subset of IDs?
    >For example I want to force the attribute "name" to only use references
    >to name-elements and "phonenumber" to only use references to
    >phone-elements, in order to not allow such thing:
    ><entry id="e1" name="p1" phonenumber="n1"/>
    >
    >how do I do that?
    >

    Hauke, you have hit the one problem that seems - and I hate to say it
    because it will make me sound like the old geek that I really am - to
    be one that only the "younger generation" of geeks actually see.

    In essence, you are viewing the _content_ of the XML document as
    divisible sections of independent code accumulated together. So that,
    for example, you have a set of fields referring to <name> tags and
    another complete and independent set referring to >phone> tags.
    Unfortunately, while set-theory and relational-set-theory are fine for
    database and object oriented work, they are nothing whatever to do
    with XML in the way you assume.

    A single XML document is a single set, which may contain defined
    subsets - but the ID and IDREF attributes are document-based and refer
    to the single main set of all tags in the document. They must, in
    short, be _unique_ within the document rather than within a subset of
    a specific range of tag names.

    This is quite deliberate. If you use an IDREF, it will validate
    document structure and content. The ID to which it refers _must_ be
    present and _must_ be unique in the document. Should you wish to use a
    subset of the document, then the proper way to handle those subsets is
    with an XPath link that more specifically defines the subset and can
    be used to validate the relation that you put in the XPath.

    If you think about it, it is quite logical and reasonable. The XML is
    a single defined set, specified by the Schema or DTD. The ID and IDREF
    is used in that set. It can also contain related subsets, where both
    the subset and the relationship is defined by the XPath statments
    within the document data - so sets and relationships are
    document-based and entirely self-contained, just as the XML as a whole
    is. It does mean that you can't simply look at an XML document and say
    "its a way of expressing a database" and assume it has the database
    functions built in - it doesn't. You must build them in (or the
    database must when it creates the XML). Like in the database, these
    relations, sets and so on need to be self-contained, self-referential
    and self-defining and in a human-readable format, just as every other
    aspect of XML does.
    Mark Preston, Oct 27, 2003
    #2
    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. rico
    Replies:
    2
    Views:
    392
  2. kevkev

    JAXB and IdRef

    kevkev, May 18, 2005, in forum: Java
    Replies:
    3
    Views:
    4,285
    kevkev
    May 19, 2005
  3. Elhanan
    Replies:
    0
    Views:
    1,120
    Elhanan
    Mar 30, 2006
  4. Lars
    Replies:
    0
    Views:
    1,182
  5. Luigi
    Replies:
    2
    Views:
    507
    Joseph Kesselman
    Dec 11, 2007
Loading...

Share This Page