restrict IDREF to special elements

H

Hauke Fuhrmann

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
 
M

Mark Preston

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top